diff --git a/apps/web/utils/outlook/client.ts b/apps/web/utils/outlook/client.ts index bbcdf42408..9c252d0520 100644 --- a/apps/web/utils/outlook/client.ts +++ b/apps/web/utils/outlook/client.ts @@ -19,6 +19,7 @@ type AuthOptions = { export class OutlookClient { private readonly client: Client; private readonly accessToken: string; + private folderIdCache: Record | null = null; constructor(accessToken: string) { this.accessToken = accessToken; @@ -45,6 +46,14 @@ export class OutlookClient { return this.accessToken; } + getFolderIdCache(): Record | null { + return this.folderIdCache; + } + + setFolderIdCache(cache: Record): void { + this.folderIdCache = cache; + } + // Helper methods for common operations async getUserProfile(): Promise { return await this.client diff --git a/apps/web/utils/outlook/message.ts b/apps/web/utils/outlook/message.ts index f8d2886859..8d13e44a5d 100644 --- a/apps/web/utils/outlook/message.ts +++ b/apps/web/utils/outlook/message.ts @@ -65,9 +65,6 @@ export function hasUnquotedParentFolderId(query: string): boolean { return /\bparentFolderId\b/.test(cleanedQuery); } -// Cache for folder IDs -let folderIdCache: Record | null = null; - // Well-known folder names in Outlook that are consistent across all languages export const WELL_KNOWN_FOLDERS = { inbox: "inbox", @@ -79,7 +76,8 @@ export const WELL_KNOWN_FOLDERS = { } as const; export async function getFolderIds(client: OutlookClient) { - if (folderIdCache) return folderIdCache; + const cachedFolderIds = client.getFolderIdCache(); + if (cachedFolderIds) return cachedFolderIds; // First get the well-known folders const wellKnownFolders = await Promise.all( @@ -101,7 +99,7 @@ export async function getFolderIds(client: OutlookClient) { }), ); - folderIdCache = wellKnownFolders.reduce( + const userFolderIds = wellKnownFolders.reduce( (acc, [key, id]) => { if (id) acc[key] = id; return acc; @@ -109,7 +107,9 @@ export async function getFolderIds(client: OutlookClient) { {} as Record, ); - return folderIdCache; + client.setFolderIdCache(userFolderIds); + + return userFolderIds; } function getOutlookLabels( diff --git a/version.txt b/version.txt index 147edff1d3..57d07874be 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.17.42 +v2.17.43