diff --git a/packages/api/src/elastic/pages.ts b/packages/api/src/elastic/pages.ts index 53e8724f2..4f29984f3 100644 --- a/packages/api/src/elastic/pages.ts +++ b/packages/api/src/elastic/pages.ts @@ -696,7 +696,7 @@ export const searchAsYouType = async ( } export const updatePages = async ( - userId: string, + ctx: PageContext, action: BulkActionType, args: PageSearchArgs, maxDocs: number, @@ -766,7 +766,7 @@ export const updatePages = async ( } // build the query - const searchBody = buildSearchBody(userId, args) + const searchBody = buildSearchBody(ctx.uid, args) .rawOption('script', updatedScript) .build() @@ -781,6 +781,7 @@ export const updatePages = async ( max_docs: maxDocs, requests_per_second: 500, // throttle the requests slices: 'auto', // parallelize the requests + refresh: ctx.refresh, }) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access @@ -789,6 +790,8 @@ export const updatePages = async ( return null } + // TODO: publish entityUpdated events for each page + if (async) { console.log('update pages task started', body.task) return body.task as string diff --git a/packages/api/src/resolvers/article/index.ts b/packages/api/src/resolvers/article/index.ts index c78cc6c2e..8c3d51d83 100644 --- a/packages/api/src/resolvers/article/index.ts +++ b/packages/api/src/resolvers/article/index.ts @@ -1110,7 +1110,7 @@ export const bulkActionResolver = authorized< async ( _parent, { query, action, labelIds, expectedCount, async }, - { claims: { uid }, log } + { claims: { uid }, log, pubsub } ) => { log.info('bulkActionResolver') @@ -1146,9 +1146,12 @@ export const bulkActionResolver = authorized< // parse query const searchQuery = parseSearchQuery(query) + // refresh index if not async + const ctx = { uid, pubsub, refresh: !async } + // start a task to update pages const taskId = await updatePages( - uid, + ctx, action, searchQuery, Math.min(expectedCount ?? 500, 500), // default and max to 500