fix(core): unused blobs query (#10350)

The default limit is 100.
This commit is contained in:
pengx17
2025-02-21 10:14:00 +00:00
parent 4d759766b9
commit 6e399ce34b
@@ -121,6 +121,11 @@ export class UnusedBlobs extends Entity {
} }
private async getUsedBlobs(): Promise<string[]> { private async getUsedBlobs(): Promise<string[]> {
const batchSize = 100;
let offset = 0;
const unusedBlobKeys: string[] = [];
while (true) {
const result = await this.docsSearchService.indexer.blockIndex.aggregate( const result = await this.docsSearchService.indexer.blockIndex.aggregate(
{ {
type: 'boolean', type: 'boolean',
@@ -132,9 +137,29 @@ export class UnusedBlobs extends Entity {
}, },
], ],
}, },
'blob' 'blob',
{
pagination: {
limit: batchSize,
skip: offset,
},
}
); );
return result.buckets.map(bucket => bucket.key);
if (!result.buckets.length) {
break;
}
unusedBlobKeys.push(...result.buckets.map(bucket => bucket.key));
offset += batchSize;
// If we got less results than the batch size, we've reached the end
if (result.buckets.length < batchSize) {
break;
}
}
return unusedBlobKeys;
} }
async hydrateBlob( async hydrateBlob(