[messaging] rename syncExternalId to syncCursor (#4752)

## Context

SyncExternalId should be renamed because this won't always represent an
id. For example, microsoft API does not use ids but dates for their
sync. Also we think external is a bit redundant so we are removing it.

Note: this field is not used by the front-end (and will probably never
be)
This commit is contained in:
Weiko 2024-04-02 18:18:43 +02:00 committed by GitHub
parent 9364a58477
commit 35ddb9acb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 18 deletions

View File

@ -170,7 +170,7 @@ export const messageChannelStandardFieldIds = {
type: '20202020-ae95-42d9-a3f1-797a2ea22122', type: '20202020-ae95-42d9-a3f1-797a2ea22122',
isContactAutoCreationEnabled: '20202020-fabd-4f14-b7c6-3310f6d132c6', isContactAutoCreationEnabled: '20202020-fabd-4f14-b7c6-3310f6d132c6',
messageChannelMessageAssociations: '20202020-49b8-4766-88fd-75f1e21b3d5f', messageChannelMessageAssociations: '20202020-49b8-4766-88fd-75f1e21b3d5f',
syncExternalId: '20202020-79d1-41cf-b738-bcf5ed61e256', syncCursor: '20202020-79d1-41cf-b738-bcf5ed61e256',
syncedAt: '20202020-263d-4c6b-ad51-137ada56f7d4', syncedAt: '20202020-263d-4c6b-ad51-137ada56f7d4',
syncStatus: '20202020-56a1-4f7e-9880-a8493bb899cc', syncStatus: '20202020-56a1-4f7e-9880-a8493bb899cc',
ongoingSyncStartedAt: '20202020-8c61-4a42-ae63-73c1c3c52e06', ongoingSyncStartedAt: '20202020-8c61-4a42-ae63-73c1c3c52e06',

View File

@ -123,9 +123,9 @@ export class MessageChannelRepository {
); );
} }
public async updateLastSyncExternalIdIfHigher( public async updateLastSyncCursorIfHigher(
id: string, id: string,
syncExternalId: string, syncCursor: string,
workspaceId: string, workspaceId: string,
transactionManager?: EntityManager, transactionManager?: EntityManager,
) { ) {
@ -133,16 +133,16 @@ export class MessageChannelRepository {
this.workspaceDataSourceService.getSchemaName(workspaceId); this.workspaceDataSourceService.getSchemaName(workspaceId);
await this.workspaceDataSourceService.executeRawQuery( await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."messageChannel" SET "syncExternalId" = $1 `UPDATE ${dataSourceSchema}."messageChannel" SET "syncCursor" = $1
WHERE "id" = $2 WHERE "id" = $2
AND ("syncExternalId" < $1 OR "syncExternalId" = '')`, AND ("syncCursor" < $1 OR "syncCursor" = '')`,
[syncExternalId, id], [syncCursor, id],
workspaceId, workspaceId,
transactionManager, transactionManager,
); );
} }
public async resetSyncExternalId( public async resetSyncCursor(
id: string, id: string,
workspaceId: string, workspaceId: string,
transactionManager?: EntityManager, transactionManager?: EntityManager,
@ -151,7 +151,7 @@ export class MessageChannelRepository {
this.workspaceDataSourceService.getSchemaName(workspaceId); this.workspaceDataSourceService.getSchemaName(workspaceId);
await this.workspaceDataSourceService.executeRawQuery( await this.workspaceDataSourceService.executeRawQuery(
`UPDATE ${dataSourceSchema}."messageChannel" SET "syncExternalId" = '' `UPDATE ${dataSourceSchema}."messageChannel" SET "syncCursor" = ''
WHERE "id" = $1`, WHERE "id" = $1`,
[id], [id],
workspaceId, workspaceId,

View File

@ -223,7 +223,7 @@ export class GmailFullSyncV2Service {
`Fetched all ${messageIdsToFetch} message ids from Gmail for messageChannel ${messageChannelId} in workspace ${workspaceId} and added to cache for import`, `Fetched all ${messageIdsToFetch} message ids from Gmail for messageChannel ${messageChannelId} in workspace ${workspaceId} and added to cache for import`,
); );
await this.updateLastSyncExternalId( await this.updateLastSyncCursor(
gmailClient, gmailClient,
messageChannelId, messageChannelId,
firstMessageExternalId, firstMessageExternalId,
@ -256,7 +256,7 @@ export class GmailFullSyncV2Service {
return blocklist.map((blocklist) => blocklist.handle); return blocklist.map((blocklist) => blocklist.handle);
} }
private async updateLastSyncExternalId( private async updateLastSyncCursor(
gmailClient: gmail_v1.Gmail, gmailClient: gmail_v1.Gmail,
messageChannelId: string, messageChannelId: string,
firstMessageExternalId: string, firstMessageExternalId: string,
@ -292,7 +292,7 @@ export class GmailFullSyncV2Service {
`Updating last external id: ${historyId} for workspace ${workspaceId} and account ${messageChannelId} succeeded.`, `Updating last external id: ${historyId} for workspace ${workspaceId} and account ${messageChannelId} succeeded.`,
); );
await this.messageChannelRepository.updateLastSyncExternalIdIfHigher( await this.messageChannelRepository.updateLastSyncCursorIfHigher(
messageChannelId, messageChannelId,
historyId, historyId,
workspaceId, workspaceId,

View File

@ -102,7 +102,7 @@ export class GmailPartialSyncV2Service {
await workspaceDataSource await workspaceDataSource
?.transaction(async (transactionManager: EntityManager) => { ?.transaction(async (transactionManager: EntityManager) => {
const lastSyncHistoryId = gmailMessageChannel.syncExternalId; const lastSyncHistoryId = gmailMessageChannel.syncCursor;
if (!lastSyncHistoryId) { if (!lastSyncHistoryId) {
this.logger.log( this.logger.log(
@ -134,7 +134,7 @@ export class GmailPartialSyncV2Service {
`404: Invalid lastSyncHistoryId: ${lastSyncHistoryId} for workspace ${workspaceId} and account ${connectedAccountId}, falling back to full sync.`, `404: Invalid lastSyncHistoryId: ${lastSyncHistoryId} for workspace ${workspaceId} and account ${connectedAccountId}, falling back to full sync.`,
); );
await this.messageChannelRepository.resetSyncExternalId( await this.messageChannelRepository.resetSyncCursor(
gmailMessageChannel.id, gmailMessageChannel.id,
workspaceId, workspaceId,
transactionManager, transactionManager,
@ -206,7 +206,7 @@ export class GmailPartialSyncV2Service {
messagesDeleted, messagesDeleted,
); );
await this.messageChannelRepository.updateLastSyncExternalIdIfHigher( await this.messageChannelRepository.updateLastSyncCursorIfHigher(
gmailMessageChannel.id, gmailMessageChannel.id,
historyId, historyId,
workspaceId, workspaceId,

View File

@ -113,16 +113,16 @@ export class MessageChannelObjectMetadata extends BaseObjectMetadata {
messageChannelMessageAssociations: MessageChannelMessageAssociationObjectMetadata[]; messageChannelMessageAssociations: MessageChannelMessageAssociationObjectMetadata[];
@FieldMetadata({ @FieldMetadata({
standardId: messageChannelStandardFieldIds.syncExternalId, standardId: messageChannelStandardFieldIds.syncCursor,
type: FieldMetadataType.TEXT, type: FieldMetadataType.TEXT,
label: 'Last sync external ID', label: 'Last sync cursor',
description: 'Last sync external ID', description: 'Last sync cursor',
icon: 'IconHistory', icon: 'IconHistory',
}) })
@Gate({ @Gate({
featureFlag: FeatureFlagKeys.IsFullSyncV2Enabled, featureFlag: FeatureFlagKeys.IsFullSyncV2Enabled,
}) })
syncExternalId: string; syncCursor: string;
@FieldMetadata({ @FieldMetadata({
standardId: messageChannelStandardFieldIds.syncedAt, standardId: messageChannelStandardFieldIds.syncedAt,