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

View File

@@ -121,20 +121,45 @@ export class UnusedBlobs extends Entity {
}
private async getUsedBlobs(): Promise<string[]> {
const result = await this.docsSearchService.indexer.blockIndex.aggregate(
{
type: 'boolean',
occur: 'must',
queries: [
{
type: 'exists',
field: 'blob',
const batchSize = 100;
let offset = 0;
const unusedBlobKeys: string[] = [];
while (true) {
const result = await this.docsSearchService.indexer.blockIndex.aggregate(
{
type: 'boolean',
occur: 'must',
queries: [
{
type: 'exists',
field: 'blob',
},
],
},
'blob',
{
pagination: {
limit: batchSize,
skip: offset,
},
],
},
'blob'
);
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(