From 0d23965fac4d5f2aa33c9373299aa06d3baba104 Mon Sep 17 00:00:00 2001 From: Adam <13007539+MrgSub@users.noreply.github.com> Date: Fri, 11 Jul 2025 13:01:19 -0700 Subject: [PATCH] getqoutauser (#1713) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Refactor Google Mail Manager quota user handling ## Description Added a new `getQuotaUser()` method to the GoogleMailManager class that combines the user's email with the current environment (`NODE_ENV`). Updated all Google API calls to use this method instead of directly using the email as the quota user. This change helps prevent quota limit issues by creating environment-specific quota user identifiers, which is particularly useful when running multiple environments (development, staging, production) with the same Google account. --- ## Type of Change - [x] ⚡ Performance improvement ## Areas Affected - [x] Email Integration (Gmail, IMAP, etc.) ## Testing Done - [x] Manual testing performed ## Checklist - [x] I have performed a self-review of my code - [x] My changes generate no new warnings ## Additional Notes This change helps prevent hitting Google API quota limits by differentiating quota usage across different environments. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._ ## Summary by CodeRabbit * **Refactor** * Improved handling of user identification for Gmail API requests to enhance consistency across different environments. --- apps/server/src/lib/driver/google.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/server/src/lib/driver/google.ts b/apps/server/src/lib/driver/google.ts index c65f7adb0..b44542ef6 100644 --- a/apps/server/src/lib/driver/google.ts +++ b/apps/server/src/lib/driver/google.ts @@ -214,6 +214,10 @@ export class GoogleMailManager implements MailManager { { email: this.config.auth?.email }, ); } + + private getQuotaUser() { + return this.config.auth?.email ? `${this.config.auth.email}-${env.NODE_ENV}` : undefined; + } public list(params: { folder: string; query?: string; @@ -235,7 +239,7 @@ export class GoogleMailManager implements MailManager { labelIds: folder === 'inbox' ? labelIds : [], maxResults, pageToken: pageToken ? pageToken : undefined, - quotaUser: this.config.auth?.email, + quotaUser: this.getQuotaUser(), }); const threads = res.data.threads ?? []; @@ -263,7 +267,7 @@ export class GoogleMailManager implements MailManager { userId: 'me', id, format: 'full', - quotaUser: this.config.auth?.email, + quotaUser: this.getQuotaUser(), }); if (!res.data.messages) @@ -787,7 +791,7 @@ export class GoogleMailManager implements MailManager { userId: 'me', id: threadId, format: 'metadata', // Fetch only metadata, - quotaUser: this.config.auth?.email, + quotaUser: this.getQuotaUser(), }); // Process res.data.messages to extract id and labelIds return {