feat(search): batch scan all tables in database search

This commit is contained in:
zipg authored and GitHub committed 2026-09-01 12:55:48 +08:00
1 parent 8f21e7af9f
commit 2e8ed4b485
12 files changed
+149 -31

No files matched your search

@@ -0,0 +1,21 @@
export const DATABASE_SEARCH_TABLE_BATCH_SIZE = 200;
export type DatabaseSearchBatchRange = {
start: number;
end: number;
};
export function databaseSearchBatchRange(nextIndex: number, total: number, scanAllRemaining = false, batchSize = DATABASE_SEARCH_TABLE_BATCH_SIZE): DatabaseSearchBatchRange {
const safeTotal = Math.max(0, Math.trunc(total));
const start = Math.min(Math.max(0, Math.trunc(nextIndex)), safeTotal);
const safeBatchSize = Math.max(1, Math.trunc(batchSize));
return {
start,
end: scanAllRemaining ? safeTotal : Math.min(start + safeBatchSize, safeTotal),
};
}
export function databaseSearchNextBatchSize(nextIndex: number, total: number, batchSize = DATABASE_SEARCH_TABLE_BATCH_SIZE): number {
const range = databaseSearchBatchRange(nextIndex, total, false, batchSize);
return range.end - range.start;
}