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

This commit is contained in:
Peng Xiao
2025-02-25 10:58:43 +08:00
committed by GitHub
parent 848145150d
commit 7e892b3a7e
@@ -121,45 +121,26 @@ export class UnusedBlobs extends Entity {
} }
private async getUsedBlobs(): Promise<string[]> { private async getUsedBlobs(): Promise<string[]> {
const batchSize = 100; const result = await this.docsSearchService.indexer.blockIndex.aggregate(
let offset = 0; {
const unusedBlobKeys: string[] = []; type: 'boolean',
occur: 'must',
while (true) { queries: [
const result = await this.docsSearchService.indexer.blockIndex.aggregate( {
{ type: 'exists',
type: 'boolean', field: 'blob',
occur: 'must',
queries: [
{
type: 'exists',
field: 'blob',
},
],
},
'blob',
{
pagination: {
limit: batchSize,
skip: offset,
}, },
} ],
); },
'blob',
if (!result.buckets.length) { {
break; pagination: {
limit: Number.MAX_SAFE_INTEGER,
},
} }
);
unusedBlobKeys.push(...result.buckets.map(bucket => bucket.key)); return 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(