Repository navigation
perf(api): spike — separate the region hierarchy from the event feed - #53
Merged
Merged
Conversation
Replace the per-navigation getRegionDoc/getChildRegions and getCountries' region read with one wholesale ['regions'] dict (every level, depth 0), cached on a long stale window. Ancestry, child lists, counts, and region routes now derive from it client-side via new region-tree helpers (indexRegions/childrenOf/ancestorIds) — dropping the feed's breadcrumb dependency for aggregation. countryCode derives from the country slug first (post-SahajCloud#556), falling back to legacyData for the pre-migration local seed (transitional). Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The geojson feed carried the localized event `title`, so a bare ['geojson'] key served stale titles after a language switch (and refetched the whole feed). Split `title` into a lean id->title sliver (GET /api/events, select title only) keyed by locale, joined back by id when building event list items. The feed is now locale-agnostic — cached once, no locale in its key — and also drops region `breadcrumbs` (~20% of its weight; ancestry comes from the regions dict). A language switch now refetches only the ~5% titles sliver. The map / search / filter surfaces read the agnostic feed directly (no title); only getRegion + getEvents join titles. Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The map renders geometry and injects its own cluster properties; the click handler needs only `id` + `webPath`. Strip every other feature property before handing the collection to the vector source, so Mapbox holds a lean geometry source instead of the full agnostic feed's card fields (address/schedule/languages/region). Demonstrates the spike finding that map-source leanness is a client-side trim, not a reason for a separate lean feed query (S2/S4). Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The feed/region/event reads carry the localized event `title`, but their query keys omitted locale — so a runtime language switch (SettingsMenu -> i18n.changeLanguage) served stale-locale titles until the entry went stale. Add `sahajLocale` to useLocale and thread it into every locale-dependent key: ['region', slug, locale], ['event', id, locale], ['events', ..., locale]. The agnostic ['geojson'], ['regions'], and ['countries'] keys stay locale-free (no localized field); ['event-titles', locale] already keys by it. Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
getRegion now throws when a region's subtree holds zero events (located or online), so the nearest ErrorBoundary renders the not-found state instead of an empty region page. Mirrors getCountries already hiding 0-event countries from the home list. Reachable only by a direct URL — region cards link only to regions that have events. Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The written finding for the spike: measured basis (wire-cost benchmark + the runtime signals verified in-browser), the S3 split decision (S1-S4 table), region-count sizing, feed weight + locale-switch cost, per-drawer latency, what the prototype implements, and the residual follow-ups (countryCode-from-slug gated on the local seed reflecting #556). Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Retire the now-dead breadcrumbs schema (RegionRefSchema.breadcrumbs +
BreadcrumbSchema) — ancestry comes from the regions dict; completes the
breadcrumb-free feed contract.
- Drop RegionIndex.childrenByParent (derivable state with a single reader that
getCountries built and never read); childrenOf is now a filter.
- toMapSource takes the features array (drop the throwaway {...data} spread).
- Comment accuracy (stale filtered-memo + getRegions notes) and finding-doc
residuals (breadcrumbs retired; locale-key query factory recommended).
Refs #32
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review follow-ups (both reviews were otherwise clean): - EventTitleSchema tolerates a null title (coalesced to '' in getEventTitles) so one bad row can't fail the whole titles read and break every title-loading view. - Drop .passthrough() from RegionNodeSchema.legacyData so the legacy blob (osmId/legacyId/mailingService/…) is stripped at the zod boundary and never reaches the public ['regions'] cache (transitional — goes with #556). - Tests: an online-only region must NOT 404 (it rolls up); a null title parses. - Doc: legacyData wire-exposure + dict-ancestry-assumption residuals. Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas with
|
| Latest commit: |
2f0f912
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d9d8b43e.sahajatlas.pages.dev |
| Branch Preview URL: | https://perf-region-feed-split.sahajatlas.pages.dev |
The widget's language codes match SahajCloud's 1:1, so the `toSahajLocale` mapping (+ its hand-maintained `SAHAJCLOUD_LOCALES` set, which had already drifted — lowercase `pt-br`, no `en-AU`) was redundant and papered over a language-set misalignment. Remove both: the interceptor now sends `i18n.resolvedLanguage` directly, and every locale-dependent query keys by plain `locale` (dropping `sahajLocale` from useLocale). SahajCloud falls back to its default for any locale it doesn't recognize (verified on /api/regions and /events/geojson), so this is safe; keeping the sets aligned is a policy — a missing language is a SahajCloud ticket (sydevs/SahajCloud#578 for hu/nl), not a client-side remap. Refs #32 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
2f0f912
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1122469d.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://perf-region-feed-split.sahajatlas-design.pages.dev |
Contributor
Author
|
Re-triggering CI — GitHub dropped the pull_request synchronize event for 8e36252 (no Actions run was created; Cloudflare deployed it fine). Reopening. |
GitHub dropped the pull_request event for the previous push (8e36252); no Actions run was created. Empty commit to re-schedule the gate. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Brings in #49 (pin-hover highlight) and #50 (date-range filter). Two conflicts, resolved by combining both sides: - Map.tsx `filtered` memo + fetch.ts `getEvents`: keep #50's `today` arg to matchesFilters AND this branch's geometry-only toMapSource trim / per-locale titles join. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived
added a commit
that referenced
this pull request
Jul 16, 2026
Resolve API-layer conflicts from the #53 region-hierarchy / event-feed split: - adopt main's RegionNode model + wholesale getRegions() tree; migrate the live-preview region-by-id read to getRegionNodeById (looks the node up in the cached tree instead of a per-region fetch) and PreviewController from RegionDoc -> RegionNode. - keep regionRoute exported for the preview controller. - fetch.test.ts: keep the shapeEventDoc import, drop the now-removed toSahajLocale; shorten a preview-secret test fixture so the merged-in security-scan hook doesn't false-positive on it. client.ts auto-merged. Gate green: lint + typecheck + 240 tests + build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Spike for #32 — restructure the data layer so the locale-agnostic region hierarchy caches once, decoupled from the per-locale event feed, and per-navigation
/api/regionsreads disappear. Prototype behind this branch; no production behaviour change to valid content. Go/no-go finding: GO with S3 — full write-up in.claude/docs/spike-32-region-feed-split.md./regionsreads — one wholesale['regions']dict (513 regions, ~105 kb) replacesgetRegionDoc+getChildRegions; ancestry / children / counts / the 0-event gate all derive from it client-side.title(andbreadcrumbs, ~20% of its weight); a ~28 kb['event-titles', locale]sliver is joined by id. A language switch now refetches ~28 kb instead of the whole ~576 kb feed (~20×), at equal cold-load.localeis now in every locale-dependent query key; the agnostic['geojson']/['regions']/['countries']keys stay locale-free.toSahajLocaleremap (+SAHAJCLOUD_LOCALES); the interceptor sendsi18n.resolvedLanguagedirectly and queries key by plainlocale. The language sets are kept aligned by policy, not a client remap (see below).Changes
src/config/api/fetch.ts— wholesalegetRegions/loadRegions;getRegion/getCountriesderive from the cached dict;getRegionDoc/getChildRegionsdropped; agnostic feed +getEventTitlestitle-join;countryCodefrom slug (refactor(state): make four implicit lifecycles explicit state machines #556) with a transitionallegacyDatafallback; 0-event 404.src/lib/shape/hierarchy.ts— region-tree helpers (indexRegions/childrenOf/ancestorIds); breadcrumb ancestry removed.src/types/{event,geojson,region,region-ref}.ts—AgnosticFeedEventSchema/EventTitleSchema/RegionNodeSchema;breadcrumbsretired.src/components/organisms/Mapbox/Map.tsx— trim feed properties to a geometry-only Mapbox source.src/config/api/client.ts+ views +useLocale— locale-dependent keys carry the activelocale; interceptor sendsi18n.resolvedLanguagedirectly (notoSahajLocale/sahajLocale)..claude/docs/spike-32-region-feed-split.md— the written go/no-go finding.Verification
pnpm lint)pnpm typecheck)pnpm test:run)pnpm build+pnpm ladle:build)Manual / visual verification
Driven in-browser (Playwright MCP) against the local
:3000seed (507 events / 513 regions):/regions— home → Belgium → Brussels fired exactly one wholesale/api/regions./api/events?select[title]&locale=fr(~28 kb) — the feed and the regions dict stayed cached./luxembourgrenders the error boundary, not an empty page.countryCoderender on name-slugs via the transitional legacy fallback./api/regions,/events/geojson,/api/events) carries the correctlocalewith the interceptor now sendingi18n.resolvedLanguagedirectly; 0 console errors.Notes for reviewer
mainis a follow-up gated on the go decision; the finding doc lists the residuals.countryCode/ refactor(state): make four implicit lifecycles explicit state machines #556. SahajCloud#556 (country slug → ISO code) is merged, but the local seed still serves name-slugs +legacyData, socountryCodeOfis slug-first with a transitionallegacyDatafallback (flags work against pre- and post-migration backends). Fully droppinglegacyData(criterion test: establish a testing strategy (local fast tests + CI smoke) #4) lands once the seed reflects refactor(state): make four implicit lifecycles explicit state machines #556.8e36252). RemovedtoSahajLocale+SAHAJCLOUD_LOCALES(which had drifted: lowercasept-br, missingen-AU) andsahajLocale. SahajCloud tolerates an unknown?locale=(falls back to its default — verified on/api/regionsand/events/geojson), so sendingi18n.resolvedLanguageraw is safe; keeping the widget's language set a subset of SahajCloud's is enforced by policy — a missing language is a SahajCloud ticket (translations: add Hungarian (hu) and Dutch (nl) locales SahajCloud#578 raised forhu/nl), not a client-side remap./code-review(correctness) +security-review— both clean, no Critical/High/Medium; their Low follow-ups are applied infb586ee.Closes #32
🤖 Generated with Claude Code