Merge pull request #2340 from omnivore-app/fix/refresh-index

fix update pages
This commit is contained in:
Hongbo Wu
2023-06-13 13:02:51 +08:00
committed by GitHub
3 changed files with 14 additions and 10 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

View File

@ -1,5 +1,6 @@
import { createOrUpdateLinkShareInfo } from '../../datalayer/links/share_info'
import { updatePage } from '../../elastic/pages'
import { env } from '../../env'
import {
ArchiveLinkError,
ArchiveLinkErrorCode,
@ -10,11 +11,8 @@ import {
UpdateLinkShareInfoErrorCode,
UpdateLinkShareInfoSuccess,
} from '../../generated/graphql'
import { authorized } from '../../utils/helpers'
import { analytics } from '../../utils/analytics'
import { env } from '../../env'
import { updatePage } from '../../elastic/pages'
import { authorized } from '../../utils/helpers'
export const updateLinkShareInfoResolver = authorized<
UpdateLinkShareInfoSuccess,
@ -81,7 +79,7 @@ export const setLinkArchivedResolver = authorized<
{
archivedAt: args.input.archived ? new Date() : null,
},
{ pubsub, uid: claims.uid }
{ pubsub, uid: claims.uid, refresh: true } // refresh index to update search results
)
} catch (e) {
return {