Only sync pages that were updated after syncedAt

This commit is contained in:
Hongbo Wu 2022-08-05 12:33:08 +08:00
parent 8e9d1fcc4f
commit c0c58bf751

View file

@ -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)