reduce bulk action batch size to 50

This commit is contained in:
Hongbo Wu 2024-07-25 10:54:21 +08:00
parent 0e0c4bddac
commit 6f12b5e406
4 changed files with 7 additions and 5 deletions

View file

@ -27,6 +27,7 @@ export const bulkAction = async (data: BulkActionData) => {
for (let offset = 0; offset < count; offset += batchSize) {
const searchArgs = {
size: batchSize,
includePending: true,
query: `(${query}) AND updated:*..${now}`, // only process items that have not been updated
}

View file

@ -25,7 +25,7 @@ export const libraryItemRepository = appDataSource
.andWhere('md5(original_url) = md5(:url)', { url })
if (forUpdate) {
qb.setLock('pessimistic_write')
qb.setLock('pessimistic_read')
}
return qb.getOne()

View file

@ -760,9 +760,10 @@ export const bulkActionResolver = authorized<
},
})
const batchSize = 100
const batchSize = 50
const searchArgs = {
query,
includePending: true,
size: 0,
}
const count = await countLibraryItems(searchArgs, uid)
@ -778,13 +779,13 @@ export const bulkActionResolver = authorized<
action,
count,
})
// if there are less than 100 items, update them synchronously
// if there are less than 50 items, update them synchronously
await batchUpdateLibraryItems(action, searchArgs, uid, labelIds, args)
return { success: true }
}
// if there are more than 100 items, update them asynchronously
// if there are more than 50 items, update them asynchronously
const data = {
userId: uid,
action,

View file

@ -1256,7 +1256,7 @@ export const batchUpdateLibraryItems = async (
const queryBuilder = getQueryBuilder(userId, em)
if (forUpdate) {
queryBuilder.setLock('pessimistic_write')
queryBuilder.setLock('pessimistic_read')
}
const libraryItems = await queryBuilder