From c0c58bf75152cdd25d670acddb579e08e669b766 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 5 Aug 2022 12:33:08 +0800 Subject: [PATCH] Only sync pages that were updated after syncedAt --- packages/api/src/routers/svc/integrations.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/api/src/routers/svc/integrations.ts b/packages/api/src/routers/svc/integrations.ts index 77d421667..74928f8e4 100644 --- a/packages/api/src/routers/svc/integrations.ts +++ b/packages/api/src/routers/svc/integrations.ts @@ -9,10 +9,11 @@ import { buildLogger } from '../../utils/logger' import { syncWithIntegration } from '../../services/integrations' import { getPageById, getPageByParam, searchPages } from '../../elastic/pages' import { Page } from '../../elastic/types' +import { DateFilter } from '../../utils/search' interface Message { - type: EntityType - data: any + type?: EntityType + data?: any userId: string } @@ -103,7 +104,15 @@ export function integrationsServiceRouter() { hasNextPage; after += size, hasNextPage = count > after ) { - ;[pages, count] = (await searchPages({ from: after, size }, userId))! + const syncedAt = integration.syncedAt + // only sync pages that were updated after syncedAt + const dateFilters: DateFilter[] = [] + syncedAt && + dateFilters.push({ field: 'updatedAt', startDate: syncedAt }) + ;[pages, count] = (await searchPages( + { from: after, size, dateFilters }, + userId + ))! const pageIds = pages.map((p) => p.id) logger.info('syncing pages', pageIds)