Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

pengx176e399ce34b32
diff --git a/packages/frontend/core/src/modules/blob-management/entity/unused-blobs.ts b/packages/frontend/core/src/modules/blob-management/entity/unused-blobs.ts
index 74406b4d21..7e1fdf5225 100644
--- a/packages/frontend/core/src/modules/blob-management/entity/unused-blobs.ts
+++ b/packages/frontend/core/src/modules/blob-management/entity/unused-blobs.ts
@@ -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(