Skip to content

Commit

Permalink
Prevent infinite loop in exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonh committed Nov 2, 2024
1 parent 44f0018 commit 37de640
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/api/src/jobs/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
})

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 37de640

Please sign in to comment.