mirror of
https://github.com/Mail-0/Zero.git
synced 2026-07-01 08:16:28 +00:00
getqoutauser (#1713)
# 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._
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **Refactor**
* Improved handling of user identification for Gmail API requests to enhance consistency across different environments.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user