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(server): team quota await (#9352)

DarkSky4ae8c2f4efcf
diff --git a/packages/backend/server/src/core/quota/storage.ts b/packages/backend/server/src/core/quota/storage.ts
index 310bd33d83..0f3a84bb0d 100644
--- a/packages/backend/server/src/core/quota/storage.ts
+++ b/packages/backend/server/src/core/quota/storage.ts
@@ -104,7 +104,7 @@ export class QuotaManagementService {
}
async getWorkspaceStorageUsage(workspaceId: string) {
- const totalSize = this.storage.totalSize(workspaceId);
+ const totalSize = await this.storage.totalSize(workspaceId);
// ensure that size is within the safe range of gql
if (Number.isSafeInteger(totalSize)) {
return totalSize;
diff --git a/packages/backend/server/tests/quota.spec.ts b/packages/backend/server/tests/quota.spec.ts
index 66ebcb5e9b..a5e91085d3 100644
--- a/packages/backend/server/tests/quota.spec.ts
+++ b/packages/backend/server/tests/quota.spec.ts
@@ -169,26 +169,44 @@ test('should be able to check with workspace quota', async t => {
const u1 = await auth.signUp('[email protected]', '123456');
const w1 = await workspace.createWorkspace(u1, null);
const w2 = await workspace.createWorkspace(u1, null);
- await quotaManager.addTeamWorkspace(w2.id, 'test');
+ const w3 = await workspace.createWorkspace(u1, null);
+ await quotaManager.addTeamWorkspace(w3.id, 'test');
{
- const wq = await quotaManager.getWorkspaceUsage(w1.id);
- t.is(wq.usedSize, 0, 'should be 0');
+ const wq1 = await quotaManager.getWorkspaceUsage(w1.id);
+ t.is(wq1.usedSize, 0, 'should be 0');
+ const wq2 = await quotaManager.getWorkspaceUsage(w2.id);
+ t.is(wq2.usedSize, 0, 'should be 0');
+ const wq3 = await quotaManager.getWorkspaceUsage(w3.id);
+ t.is(wq3.usedSize, 0, 'should be 0');
}
{
await workspaceBlob.put(w1.id, 'test', Buffer.from([0, 0]));
+ await workspaceBlob.put(w2.id, 'test', Buffer.from([0, 0]));
+
+ // normal workspace
const wq1 = await quotaManager.getWorkspaceUsage(w1.id);
- t.is(wq1.usedSize, 2, 'should be 2');
+ t.is(wq1.usedSize, 4, 'should share usage with w2');
const wq2 = await quotaManager.getWorkspaceUsage(w2.id);
- t.is(wq2.usedSize, 0, 'should be 0');
+ t.is(wq2.usedSize, 4, 'should share usage with w1');
+
+ // workspace with quota
+ const wq3 = await quotaManager.getWorkspaceUsage(w3.id);
+ t.is(wq3.usedSize, 0, 'should not share usage with w1 and w2');
}
{
- await workspaceBlob.put(w2.id, 'test', Buffer.from([0, 0, 0]));
+ await workspaceBlob.put(w3.id, 'test', Buffer.from([0, 0, 0]));
+
+ // normal workspace
const wq1 = await quotaManager.getWorkspaceUsage(w1.id);
- t.is(wq1.usedSize, 2, 'should be 2');
+ t.is(wq1.usedSize, 4, 'should not share usage with w3');
const wq2 = await quotaManager.getWorkspaceUsage(w2.id);
- t.is(wq2.usedSize, 3, 'should be 0');
+ t.is(wq2.usedSize, 4, 'should not share usage with w3');
+
+ // workspace with quota
+ const wq3 = await quotaManager.getWorkspaceUsage(w3.id);
+ t.is(wq3.usedSize, 3, 'should not share usage with w1 and w2');
}
});