diff --git a/packages/api/src/jobs/export.ts b/packages/api/src/jobs/export.ts index e5deb2ce0..82c12a488 100644 --- a/packages/api/src/jobs/export.ts +++ b/packages/api/src/jobs/export.ts @@ -5,6 +5,7 @@ import { TaskState } from '../generated/graphql' import { findExportById, saveExport } from '../services/export' import { findHighlightsByLibraryItemId } from '../services/highlights' import { + countLibraryItems, findLibraryItemById, searchLibraryItems, } from '../services/library_item' @@ -163,7 +164,17 @@ export const exportJob = async (jobData: ExportJobData) => { return } - logger.info('exporting all items...', { + const itemCount = await countLibraryItems( + { + query: 'in:all', + includeContent: false, + includeDeleted: false, + includePending: false, + }, + userId + ) + + logger.info(`exporting ${itemCount} items...`, { userId, }) @@ -230,8 +241,17 @@ export const exportJob = async (jobData: ExportJobData) => { const size = items.length // write data to the csv file if (size > 0) { - cursor = await uploadToBucket(userId, items, cursor, size, archive) - + let nextCursor = await uploadToBucket( + userId, + items, + cursor, + size, + archive + ) + if (nextCursor == cursor) { + break + } + cursor = nextCursor hasNext = size === batchSize } } while (hasNext)