mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
@@ -121,20 +121,45 @@ export class UnusedBlobs extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getUsedBlobs(): Promise<string[]> {
|
private async getUsedBlobs(): Promise<string[]> {
|
||||||
const result = await this.docsSearchService.indexer.blockIndex.aggregate(
|
const batchSize = 100;
|
||||||
{
|
let offset = 0;
|
||||||
type: 'boolean',
|
const unusedBlobKeys: string[] = [];
|
||||||
occur: 'must',
|
|
||||||
queries: [
|
while (true) {
|
||||||
{
|
const result = await this.docsSearchService.indexer.blockIndex.aggregate(
|
||||||
type: 'exists',
|
{
|
||||||
field: 'blob',
|
type: 'boolean',
|
||||||
|
occur: 'must',
|
||||||
|
queries: [
|
||||||
|
{
|
||||||
|
type: 'exists',
|
||||||
|
field: 'blob',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'blob',
|
||||||
|
{
|
||||||
|
pagination: {
|
||||||
|
limit: batchSize,
|
||||||
|
skip: offset,
|
||||||
},
|
},
|
||||||
],
|
}
|
||||||
},
|
);
|
||||||
'blob'
|
|
||||||
);
|
if (!result.buckets.length) {
|
||||||
return result.buckets.map(bucket => bucket.key);
|
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(
|
||||||
|
|||||||
Reference in New Issue
Block a user