Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(search-indexer): Only calculate folder hash on initial iteration #16084

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const envs = {
prod: 'cdn.contentful.com',
},
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: {
dev: '20',
dev: '40',
staging: '40',
prod: '40',
},
Expand Down
4 changes: 2 additions & 2 deletions charts/islandis/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ search-indexer-service:
env:
AIR_DISCOUNT_SCHEME_FRONTEND_HOSTNAME: 'loftbru.dev01.devland.is'
APPLICATION_URL: 'http://search-indexer-service'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '20'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '40'
CONTENTFUL_ENVIRONMENT: 'master'
CONTENTFUL_HOST: 'preview.contentful.com'
CONTENTFUL_SPACE: '8k0h54kbe6bj'
Expand Down Expand Up @@ -2036,7 +2036,7 @@ search-indexer-service:
env:
AIR_DISCOUNT_SCHEME_FRONTEND_HOSTNAME: 'loftbru.dev01.devland.is'
APPLICATION_URL: 'http://search-indexer-service'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '20'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '40'
CONTENTFUL_ENVIRONMENT: 'master'
CONTENTFUL_HOST: 'preview.contentful.com'
CONTENTFUL_SPACE: '8k0h54kbe6bj'
Expand Down
40 changes: 22 additions & 18 deletions libs/cms/src/lib/search/cmsSync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,35 +184,39 @@ export class CmsSyncService implements ContentSearchImporter<PostSyncOptions> {
options: SyncOptions,
): Promise<SyncResponse<PostSyncOptions> | null> {
logger.info('Doing cms sync', options)
let cmsSyncOptions: SyncOptions
let cmsSyncOptions: SyncOptions = options

/**
* We don't want full sync to run every time we start a new pod
* We want full sync to run once when the first pod initializes the first container
* and then never again until a new index is deployed
*/
let folderHash
let folderHash = options.folderHash

if (options.syncType === 'initialize') {
const { elasticIndex = getElasticsearchIndex(options.locale) } = options

folderHash = await this.getModelsFolderHash()
const lastFolderHash = await this.getLastFolderHash(elasticIndex)
if (folderHash !== lastFolderHash) {
logger.info(
'Folder and index folder hash do not match, running full sync',
{ locale: options.locale },
)
cmsSyncOptions = { ...options, syncType: 'full' }
} else {
logger.info('Folder and index folder hash match, skipping sync', {
locale: options.locale,
})
// we skip import if it is not needed
return null
cmsSyncOptions = { ...options, syncType: 'full' }
if (folderHash === undefined) {
folderHash = await this.getModelsFolderHash()
const lastFolderHash = await this.getLastFolderHash(elasticIndex)
if (folderHash !== lastFolderHash) {
logger.info(
'Folder and index folder hash do not match, running full sync',
{ locale: options.locale },
)
} else {
logger.info('Folder and index folder hash match, skipping sync', {
locale: options.locale,
})
// we skip import if it is not needed
return null
}
}
} else if (options.syncType === 'full') {
cmsSyncOptions = options
folderHash = await this.getModelsFolderHash() // we know full will update all models so we can set the folder hash here
if (folderHash === undefined) {
folderHash = await this.getModelsFolderHash() // we know full will update all models so we can set the folder hash here
}
} else {
cmsSyncOptions = options
folderHash = '' // this will always be a partial update so we don't want to update folder hash
Expand Down
2 changes: 1 addition & 1 deletion libs/cms/src/lib/search/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class ContentfulService {
nestedItems,
} = await this.getPopulatedSyncEntries(typeOfSync, locale, chunkSize)

const isDeltaUpdate = syncType !== 'full'
const isDeltaUpdate = syncType === 'fromLast'

let shouldResolveNestedEntries = false
if (environment.runtimeEnvironment === 'local') {
Expand Down
3 changes: 2 additions & 1 deletion libs/content-search-indexer/src/lib/indexing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class IndexingService {
const importerResponse = await importer.doSync({
...options,
nextPageToken,
folderHash: postSyncOptions?.folderHash,
})

// importers can skip import by returning null
Expand Down Expand Up @@ -111,7 +112,7 @@ export class IndexingService {
postSyncOptions = { ...postSyncOptions, token: nextSyncToken }
}

if (importer.postSync) {
if (postSyncOptions && importer.postSync) {
logger.info('Importer started post sync', {
importer: importer.constructor.name,
index: elasticIndex,
Expand Down
1 change: 1 addition & 0 deletions libs/content-search-indexer/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SyncOptions {
syncType: 'full' | 'fromLast' | 'initialize'
elasticIndex?: string
nextPageToken?: string
folderHash?: string
}

export interface SyncResponse<PostSyncOptionsType = any> {
Expand Down
Loading