reduce size

This commit is contained in:
Hongbo Wu
2024-02-02 15:45:11 +08:00
parent e980be7771
commit 54a4022409
3 changed files with 11 additions and 10 deletions

View File

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

View File

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

View File

@ -972,9 +972,9 @@ export const batchUpdateLibraryItems = async (
const getLibraryItemIds = async (
userId: string,
em: EntityManager
): Promise<string[]> => {
): 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