diff --git a/packages/api/src/jobs/bulk_action.ts b/packages/api/src/jobs/bulk_action.ts index abea14493..56a38f282 100644 --- a/packages/api/src/jobs/bulk_action.ts +++ b/packages/api/src/jobs/bulk_action.ts @@ -28,7 +28,7 @@ export const bulkAction = async (data: BulkActionData) => { do { const searchArgs = { size: batchSize, - query: `(${query}) AND updated:<${now}`, + query: `(${query}) AND updated:*..${now}`, // only process items that have not been updated } try { diff --git a/packages/api/src/resolvers/article/index.ts b/packages/api/src/resolvers/article/index.ts index 04666c7dc..a33e828f5 100644 --- a/packages/api/src/resolvers/article/index.ts +++ b/packages/api/src/resolvers/article/index.ts @@ -878,7 +878,7 @@ export const bulkActionResolver = authorized< const batchSize = 100 const searchArgs = { query, - size: batchSize, + size: 0, } const searchResult = await searchLibraryItems(searchArgs, uid) const count = searchResult.count @@ -888,6 +888,7 @@ export const bulkActionResolver = authorized< } if (count <= batchSize) { + searchArgs.size = count // if there are less than 100 items, update them synchronously await batchUpdateLibraryItems(action, searchArgs, uid, labelIds, args) diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index 5399c3453..dd2384a71 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -972,9 +972,9 @@ export const batchUpdateLibraryItems = async ( const getLibraryItemIds = async ( userId: string, em: EntityManager - ): Promise => { + ): Promise<{ id: string }[]> => { const queryBuilder = getQueryBuilder(userId, em) - return queryBuilder.select('library_item.id').getRawMany() + return queryBuilder.select('library_item.id', 'id').getRawMany() } if (!searchArgs.query) { @@ -1006,27 +1006,27 @@ export const batchUpdateLibraryItems = async ( throw new Error('Labels are required for this action') } - const libraryItemIds = await authTrx( + const libraryItems = await authTrx( async (tx) => getLibraryItemIds(userId, tx), undefined, userId ) // add labels to library items - for (const libraryItemId of libraryItemIds) { - await addLabelsToLibraryItem(labelIds, libraryItemId, userId) + for (const libraryItem of libraryItems) { + await addLabelsToLibraryItem(labelIds, libraryItem.id, userId) } return } case BulkActionType.MarkAsRead: { - const libraryItemIds = await authTrx( + const libraryItems = await authTrx( async (tx) => getLibraryItemIds(userId, tx), undefined, userId ) // update reading progress for library items - for (const libraryItemId of libraryItemIds) { - await markItemAsRead(libraryItemId, userId) + for (const libraryItem of libraryItems) { + await markItemAsRead(libraryItem.id, userId) } return