From becfa5bb57b1e4373693afb47bd54c902ae76f09 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 7 Jul 2026 10:30:04 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20tenant=20access?= =?UTF-8?q?=20resolution=20by=20bypassing=20redundant=20db=20queries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: brycejohnson1417 <257422776+brycejohnson1417@users.noreply.github.com> --- .jules/bolt.md | 3 +++ .../auth/tenant-access-selection.ts | 4 ++-- lib/application/auth/tenant-access.ts | 22 ++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..28e153f --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-07-07 - Optimize workspace compilation in auth routing +**Learning:** When resolving tenant access, we often have the full `Organization` object pre-fetched from a list or lookup. Calling the React `cache()` wrapped `getWorkspaceExperienceBySlug` discards this pre-fetched object and causes redundant database queries. We shouldn't add the pre-fetched object to the cache signature because it fragments the cache key. +**Action:** Bypass the cached data-fetching method (`getWorkspaceExperienceBySlug`) and directly call the internal synchronous compiler (`compileWorkspaceExperience`) when the full `Organization` object is already available in the application layer. Ensure `settings` property is passed safely by using a generic type map lookup rather than `as any` type assertions. diff --git a/lib/application/auth/tenant-access-selection.ts b/lib/application/auth/tenant-access-selection.ts index 75e45ac..ffe475b 100644 --- a/lib/application/auth/tenant-access-selection.ts +++ b/lib/application/auth/tenant-access-selection.ts @@ -8,9 +8,9 @@ export interface MembershipSelectionOrganization { slug: string; } -export function selectMembershipOrganization(input: { +export function selectMembershipOrganization(input: { memberships: MembershipSelectionMember[]; - organizationsById: Map; + organizationsById: Map; requestedSlug?: string | null; }) { const requestedSlug = input.requestedSlug?.trim() || null; diff --git a/lib/application/auth/tenant-access.ts b/lib/application/auth/tenant-access.ts index 09f0d27..f5377a3 100644 --- a/lib/application/auth/tenant-access.ts +++ b/lib/application/auth/tenant-access.ts @@ -12,6 +12,7 @@ import { } from "@/lib/application/auth/tenant-routing"; import { selectMembershipOrganization } from "@/lib/application/auth/tenant-access-selection"; import { getWorkspaceExperienceBySlug } from "@/lib/application/workspace/workspace-service"; +import { compileWorkspaceExperience } from "@/lib/platform/workspace/compiler"; import { OrganizationMemberRepository } from "@/lib/infrastructure/supabase/organization-member-repository"; import { OrganizationRepository } from "@/lib/infrastructure/supabase/organization-repository"; import { resolveWorkspaceTemplateForEmailDomain } from "@/lib/platform/workspace/registry"; @@ -110,7 +111,12 @@ export async function resolveTenantAccess( }); if (organization) { - const workspace = await getWorkspaceExperienceBySlug(organization.slug); + // ⚡ Bolt: Using synchronous `compileWorkspaceExperience` directly since the full `Organization` object is already available in the map. + // 📊 Impact: Bypasses the `getWorkspaceExperienceBySlug` cache fetch which causes redundant DB lookups since the `Organization` object cannot be safely passed to the React cache key. + const workspace = compileWorkspaceExperience({ + slug: organization.slug, + organization, + }); return existingWorkspaceAccess({ slug: organization.slug, name: organization.name, @@ -124,7 +130,12 @@ export async function resolveTenantAccess( if (emailDomain) { const workspaceOrganization = await organizations.findFirstByWorkspaceEmailDomain(emailDomain); if (workspaceOrganization && (!requestedSlug || workspaceOrganization.slug === requestedSlug)) { - const workspace = await getWorkspaceExperienceBySlug(workspaceOrganization.slug); + // ⚡ Bolt: Using synchronous `compileWorkspaceExperience` directly since the full `Organization` object was fetched above. + // 📊 Impact: Saves a redundant DB query on login. + const workspace = compileWorkspaceExperience({ + slug: workspaceOrganization.slug, + organization: workspaceOrganization, + }); return existingWorkspaceAccess({ slug: workspaceOrganization.slug, name: workspaceOrganization.name, @@ -143,7 +154,12 @@ export async function resolveTenantAccess( if (guessed.slug) { const existingOrganization = await organizations.findBySlug(guessed.slug).catch(() => null); if (existingOrganization) { - const workspace = await getWorkspaceExperienceBySlug(existingOrganization.slug); + // ⚡ Bolt: Using synchronous `compileWorkspaceExperience` directly since the full `Organization` object was fetched above. + // 📊 Impact: Saves a redundant DB query on login. + const workspace = compileWorkspaceExperience({ + slug: existingOrganization.slug, + organization: existingOrganization, + }); return existingWorkspaceAccess({ slug: existingOrganization.slug, name: existingOrganization.name,