refresh index if update is not async

This commit is contained in:
Hongbo Wu
2023-06-13 12:43:18 +08:00
parent 2b6603b08d
commit 771114b30d
2 changed files with 10 additions and 4 deletions

View File

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

View File

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