Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-24 - [Avoid React cache key fragmentation]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required run report and registry update

This changes runtime behavior in tenant resolution and account geocoding, but records the work only in the bot-specific .jules/bolt.md; there is no corresponding docs/runs/ report or docs/WORK_REGISTRY.json update. That leaves the autonomous execution queue and the slice's validation/remaining-risk record stale, contrary to the repository's required workflow for meaningful implementation slices.

AGENTS.md reference: AGENTS.md:L35-L39

Useful? React with πŸ‘Β / πŸ‘Ž.

**Learning:** When avoiding redundant database queries for service methods wrapped in Reacts cache() (e.g., getWorkspaceExperienceBySlug), do not add optional pre-fetched objects to the function signature, as Reacts cache keys off all arguments and this will fragment the cache. Instead, bypass the cached data-fetching method and directly call the internal synchronous compiler (e.g., compileWorkspaceExperience) from the application layer when the data is already available.
**Action:** Replace `getWorkspaceExperienceBySlug(organization.slug)` calls with `compileWorkspaceExperience({slug: organization.slug, organization})` when `organization` is already loaded.
11 changes: 8 additions & 3 deletions lib/application/auth/tenant-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -110,7 +111,11 @@ export async function resolveTenantAccess(
});

if (organization) {
const workspace = await getWorkspaceExperienceBySlug(organization.slug);
const fullOrganization = organizationsById.get(organization.id);
const workspace = fullOrganization
? compileWorkspaceExperience({ slug: fullOrganization.slug, organization: fullOrganization })
: await getWorkspaceExperienceBySlug(organization.slug);

return existingWorkspaceAccess({
slug: organization.slug,
name: organization.name,
Expand All @@ -124,7 +129,7 @@ export async function resolveTenantAccess(
if (emailDomain) {
const workspaceOrganization = await organizations.findFirstByWorkspaceEmailDomain(emailDomain);
if (workspaceOrganization && (!requestedSlug || workspaceOrganization.slug === requestedSlug)) {
const workspace = await getWorkspaceExperienceBySlug(workspaceOrganization.slug);
const workspace = compileWorkspaceExperience({ slug: workspaceOrganization.slug, organization: workspaceOrganization });
return existingWorkspaceAccess({
slug: workspaceOrganization.slug,
name: workspaceOrganization.name,
Expand All @@ -143,7 +148,7 @@ export async function resolveTenantAccess(
if (guessed.slug) {
const existingOrganization = await organizations.findBySlug(guessed.slug).catch(() => null);
if (existingOrganization) {
const workspace = await getWorkspaceExperienceBySlug(existingOrganization.slug);
const workspace = compileWorkspaceExperience({ slug: existingOrganization.slug, organization: existingOrganization });
return existingWorkspaceAccess({
slug: existingOrganization.slug,
name: existingOrganization.name,
Expand Down
4 changes: 2 additions & 2 deletions lib/application/runtime/geocode-accounts-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
hasUsableWorkspaceAddress,
resolveSuppressedGeocodingAddress,
} from "@/lib/application/runtime/geocoding-policy";
import { getWorkspaceExperienceBySlug } from "@/lib/application/workspace/workspace-service";
import { compileWorkspaceExperience } from "@/lib/platform/workspace/compiler";
import { geocodeAccountCandidate, resolveGeocodingPlan, type GeocodeCandidate } from "@/lib/infrastructure/adapters/geocoding/geocoding";
import { getSupabaseAdminClient } from "@/lib/supabase/admin";

Expand Down Expand Up @@ -49,7 +49,7 @@ export async function geocodeMissingRuntimeAccounts(input: { organizationSlug: s
organizationId: organization.id,
organizationSlug: organization.slug,
});
const workspace = await getWorkspaceExperienceBySlug(organization.slug);
const workspace = compileWorkspaceExperience({ slug: organization.slug, organization });
const geocodingConfig = workspace.workspace.geocoding ?? null;
const limit = readLimit(input.limit, plan.maxPerSync, plan.maxPerSync);
const supabase = getSupabaseAdminClient() as any;
Expand Down
Loading