fix tests

This commit is contained in:
Hongbo Wu
2024-01-31 23:19:35 +08:00
parent 702bd6c3c6
commit 2a0e6f8fa4
2 changed files with 21 additions and 20 deletions

View File

@ -12,12 +12,22 @@ export interface BulkActionData {
labelIds: string[]
batchSize: number
args?: unknown
useFolders?: boolean
}
export const BULK_ACTION_JOB_NAME = 'bulk-action'
export const bulkAction = async (data: BulkActionData) => {
const { userId, action, query, labelIds, count, args, batchSize } = data
const {
userId,
action,
query,
labelIds,
count,
args,
batchSize,
useFolders,
} = data
const queue = await getBackendQueue()
if (!queue) {
@ -31,6 +41,7 @@ export const bulkAction = async (data: BulkActionData) => {
size: batchSize,
from: offset,
query,
useFolders,
}
const searchResult = await searchLibraryItems(searchArgs, userId)

View File

@ -879,15 +879,13 @@ export const bulkActionResolver = authorized<
},
})
const searchResult = await searchLibraryItems(
{
query,
includePending: true,
includeDeleted: true,
useFolders: query.includes('use:folders'),
},
uid
)
const useFolders = query.includes('use:folders')
const searchArgs = {
query,
size: 0,
useFolders,
}
const searchResult = await searchLibraryItems(searchArgs, uid)
const count = searchResult.count
if (count === 0) {
log.info('No items found for bulk action')
@ -897,16 +895,7 @@ export const bulkActionResolver = authorized<
const batchSize = 100
if (count <= batchSize) {
// if there are less than 100 items, update them synchronously
await batchUpdateLibraryItems(
action,
{
query,
useFolders: query.includes('use:folders'),
},
uid,
labelIds,
args
)
await batchUpdateLibraryItems(action, searchArgs, uid, labelIds, args)
return { success: true }
}
@ -925,6 +914,7 @@ export const bulkActionResolver = authorized<
count,
args,
batchSize,
useFolders,
}
await queue.add(BULK_ACTION_JOB_NAME, data, {
attempts: 1,