From 52253e9e8288fbc15f42a8e3a1006ccf959bd54d Mon Sep 17 00:00:00 2001 From: EYHN Date: Thu, 8 May 2025 09:14:54 +0000 Subject: [PATCH] fix(nbstore): update workspace blob quota query (#12191) Change the query for querying quota of Cloud Blob Storage. The original query used new fields, which caused errors in the old version of the server. This PR uses a simpler query to ensure compatibility. ## Summary by CodeRabbit - **New Features** - Added the ability to retrieve a workspace's blob storage quota, including both the raw limit and a human-readable format, via a new query. - **Bug Fixes** - Updated quota retrieval to use the new blob-specific quota query for improved accuracy. --- packages/common/graphql/src/graphql/index.ts | 15 ++++++++++++ .../src/graphql/workspace-blob-quota.gql | 10 ++++++++ packages/common/graphql/src/schema.ts | 24 +++++++++++++++++++ .../common/nbstore/src/impls/cloud/blob.ts | 4 ++-- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 packages/common/graphql/src/graphql/workspace-blob-quota.gql diff --git a/packages/common/graphql/src/graphql/index.ts b/packages/common/graphql/src/graphql/index.ts index ce603e7124..262d0620c5 100644 --- a/packages/common/graphql/src/graphql/index.ts +++ b/packages/common/graphql/src/graphql/index.ts @@ -1701,6 +1701,21 @@ export const verifyEmailMutation = { }`, }; +export const workspaceBlobQuotaQuery = { + id: 'workspaceBlobQuotaQuery' as const, + op: 'workspaceBlobQuota', + query: `query workspaceBlobQuota($id: String!) { + workspace(id: $id) { + quota { + blobLimit + humanReadable { + blobLimit + } + } + } +}`, +}; + export const getWorkspaceConfigQuery = { id: 'getWorkspaceConfigQuery' as const, op: 'getWorkspaceConfig', diff --git a/packages/common/graphql/src/graphql/workspace-blob-quota.gql b/packages/common/graphql/src/graphql/workspace-blob-quota.gql new file mode 100644 index 0000000000..0b8a57f888 --- /dev/null +++ b/packages/common/graphql/src/graphql/workspace-blob-quota.gql @@ -0,0 +1,10 @@ +query workspaceBlobQuota($id: String!) { + workspace(id: $id) { + quota { + blobLimit + humanReadable { + blobLimit + } + } + } +} diff --git a/packages/common/graphql/src/schema.ts b/packages/common/graphql/src/schema.ts index fe61473749..6018eb0886 100644 --- a/packages/common/graphql/src/schema.ts +++ b/packages/common/graphql/src/schema.ts @@ -4387,6 +4387,25 @@ export type VerifyEmailMutation = { verifyEmail: boolean; }; +export type WorkspaceBlobQuotaQueryVariables = Exact<{ + id: Scalars['String']['input']; +}>; + +export type WorkspaceBlobQuotaQuery = { + __typename?: 'Query'; + workspace: { + __typename?: 'WorkspaceType'; + quota: { + __typename?: 'WorkspaceQuotaType'; + blobLimit: number; + humanReadable: { + __typename?: 'WorkspaceQuotaHumanReadableType'; + blobLimit: string; + }; + }; + }; +}; + export type GetWorkspaceConfigQueryVariables = Exact<{ id: Scalars['String']['input']; }>; @@ -4867,6 +4886,11 @@ export type Queries = variables: SubscriptionQueryVariables; response: SubscriptionQuery; } + | { + name: 'workspaceBlobQuotaQuery'; + variables: WorkspaceBlobQuotaQueryVariables; + response: WorkspaceBlobQuotaQuery; + } | { name: 'getWorkspaceConfigQuery'; variables: GetWorkspaceConfigQueryVariables; diff --git a/packages/common/nbstore/src/impls/cloud/blob.ts b/packages/common/nbstore/src/impls/cloud/blob.ts index 9e624f0429..cec0a5c9f6 100644 --- a/packages/common/nbstore/src/impls/cloud/blob.ts +++ b/packages/common/nbstore/src/impls/cloud/blob.ts @@ -4,7 +4,7 @@ import { listBlobsQuery, releaseDeletedBlobsMutation, setBlobMutation, - workspaceQuotaQuery, + workspaceBlobQuotaQuery, } from '@affine/graphql'; import { @@ -161,7 +161,7 @@ export class CloudBlobStorage extends BlobStorageBase { } try { const res = await this.connection.gql({ - query: workspaceQuotaQuery, + query: workspaceBlobQuotaQuery, variables: { id: this.options.id }, });