Skip to content

perf(api): spike — separate region hierarchy from the event feed #32

Closed

Description

@Ardnived

Summary

Restructure the widget's data layer so the locale-agnostic region hierarchy is
fetched and cached once
, decoupled from the per-locale event data, and the
per-navigation /api/regions reads disappear. Today one ['geojson'] feed serves the
map, the hierarchy's counts/bounds, and the event lists, while the hierarchy is
re-read from /api/regions on every navigation. This spike settles the event-data
split (below) and measures the win.

Context — what's actually localized (verified against SahajCloud)

  • Event title is the only localized: true field in the feed's selected fields
    (Events.ts). Region name/subtitle are not localized ("identical in every
    locale"); breadcrumbs are localized: false. Address is factual text; schedule is
    dates. So the region hierarchy — and every event field except title — is agnostic.
  • The current key ['geojson'] omits locale, yet a runtime language switcher exists
    (SettingsMenu → i18n.changeLanguage), so a switch serves stale-locale titles until
    the feed goes stale. Locale must be in the key of any locale-dependent query.
  • The /events/geojson endpoint is a thin pass-through of the client's
    select/populate (+ HTTP cache headers), so this is client-side query
    restructuring — no feed/endpoint change required.

Settled structure

  • ['regions'] — full region hierarchy (agnostic, cache-once). One wholesale
    /api/regions read (high limit; select slug/name/subtitle/level/parent/webPath/
    webUrl) replacing per-navigation getRegionDoc + getChildRegions + getCountries'
    regions read. Countries/subregions/ancestors and the 0-event 404 gate derive from
    this + counts from the event data, client-side. Its own query regardless of the split
    below (regions change on a different, slower cadence than events).
  • ['event', id, locale] — full detail on-demand. EventView / ShareView /
    RegistrationView (description HTML, images, registration, contact). Exists today;
    ensure locale is in the key.

Open question — how to split the event point/card data (spike to choose)

Only title is localized; geometry + every other card field (schedule, address,
languages, eventType, region name/slug, path, coords) is agnostic. Two independent axes
pull on the split — map-source leanness (Mapbox should parse geometry only) and
locale-switch refetch (only title changes) — and each candidate optimizes a
different one:

Split Event queries Map source On locale switch
S1 — one fat feed (default) ['geojson', locale] (geometry + full card basics + title) fat refetch all
S2 — lean backbone + cohesive cards ['geojson'] (geometry + ancestry) + ['event-cards', locale] (all display incl. title) lean refetch cards (incl. agnostic bulk)
S3 — agnostic feed + titles sliver ['geojson'] (geometry + basics) + ['event-titles', locale] (id→title) fat titles only
S4 — full split lean ['geojson'] + ['event-basics'] (agnostic) + ['event-titles', locale] lean titles only
  • S2 optimizes the map source but still refetches the agnostic bulk (address/schedule)
    on a language switch
    — it does not buy locale-cache-efficiency.
  • S3 buys that (only title refetches) but keeps a fat map source (+ a titles-only
    query and a by-id join).
  • S4 buys both, at three event queries + joins.
  • S1 is simplest: one cohesive per-locale record per card, no join.

Decision criteria: event count / feed weight (heavy → favor a lean geometry feed,
S2/S4), locale-switch frequency (high → S3/S4), complexity budget (favor S1).

Measured findings — wire-cost benchmark (local seed: 487 events, 513 regions)

Ran a curl/qs matrix against local :3000, raw bytes (gzip would compress repetitive
fields ~5–8×). Region count is 513 (29 country / 98 region / 346 city / 40 center) —
the wholesale ['regions'] read is 105 kb / 513 docs, so the "regions too big" worry
is unfounded at this scale.

Candidate cold-load map-source per-locale-switch queries
S1 fat feed 681 kb 576 kb 576 kb 2
S2 lean + cards 726 kb 223 kb 399 kb 3
S3 agnostic + titles 687 kb 553 kb 28 kb 3
S4 lean + basics + titles 859 kb 223 kb 28 kb 4

Three results:

  1. title is ~28 kb (≈5% of the feed). Isolating it (S3/S4) cuts the locale-switch
    refetch 576 kb → 28 kb (~20×) at equal cold-load and one tiny extra query + a
    by-id join. The locale win is nearly free.
  2. S2 is empirically dominated — 726 kb cold and a 399 kb switch (its "cards" query
    bundles agnostic basics with the title). Confirms it's the worst-of-both. Drop it.
  3. Breadcrumbs are ~112 kb (20%) of the feed. Since the wholesale regions dict carries
    parentId chains, event ancestry can be walked client-side from each event's direct
    region id — so breadcrumbs can be dropped from the feed: agnostic 553→441 kb,
    lean 223→121 kb. A free ~20% cut in every candidate (independent of S1–S4).

Also: map-source leanness is a client-side concern — trim feature properties to
geometry before handing the collection to Mapbox — so it does not require the separate
lean query that S2/S4 assume. That removes most of S4's rationale at this scale.

Recommendation (measured): S3, breadcrumb-free, + the wholesale regions dict. One
agnostic feed (~441 kb, ancestry from the dict) + a 28 kb per-locale titles map joined by
id + the 105 kb cache-once regions dict; Mapbox gets a client-side-trimmed geometry view.
S1 (breadcrumb-free, title in feed) stays the simplicity fallback if locale-switching is
truly nil — it's cold-equal, just 20× costlier per switch. S4 only earns its 4th query if
event count reaches the many-thousands where a fetched lean feed beats a client-side trim.

Spike tasks

  • Measure current per-drawer latency (the /regions reads), feed warm/cold, throttled network.
  • Prototype the settled part client-side (no server change): wholesale ['regions']; getCountries/getRegion derive from cache; drop getRegionDoc/getChildRegions.
  • Confirm both list surfaces render (with titles): RegionView (region events) and SearchView / DynamicEventsList (global distance, incl. online events).
  • Confirm a 0-event region 404s (client count-join against the event data).
  • Size the wholesale ['regions'] read — total region count incl. center (venue) leaves; if it's many thousands, evaluate pagination or a slim server region-tree endpoint (separate SahajCloud ticket).
  • Choose the event-data split (S1–S4): measure event count / feed payload weight (map-source cost) and locale-switch refetch cost; pick the simplest split that clears the measured bottleneck. Default S1.
  • Produce a go/no-go + final field selects.

Acceptance criteria

  • A written finding: latency saved per drawer, region-count sizing, feed weight + locale-switch cost, and a recommended event-data split (S1–S4) with its measured basis.
  • A working local prototype: no per-navigation /regions reads; both list surfaces render; the hierarchy stays cached across locale switches.
  • 0-event regions 404; locale is in the key of every locale-dependent query and absent from ['regions'] + any agnostic feed.
  • countryCode read from the country slug (paired with feat(regions): country slug = ISO alpha-2 code (drop legacyData) SahajCloud#556); legacyData / countryCodeOf no longer referenced in fetch.ts.
  • No production behavior change from the spike itself (prototype behind a branch); shipping is a follow-up gated on the go decision.

How the optimal split is chosen (the spike's method)

Every candidate — S1–S4, the wholesale ['regions'], a titles map — is just a different
select/populate against endpoints that already exist and pass selects straight
through
(/events/geojson, /api/regions, /api/events). So choosing the winner needs
no SahajCloud change and no worktree, and most of it needs no frontend:

  • Wire-cost benchmark (API-level, no frontend, no server change): a curl/script matrix
    against the running local :3000 — one row per candidate query — recording payload
    bytes, request count, region-list size/count, titles-map size, and the decisive
    metric: what re-downloads on a locale switch (agnostic cache-once vs per-locale).
    This settles most of "which is cheapest on the wire." It belongs to this spike (it
    compares client query strategies, not the server) but runs entirely over HTTP.
  • Runtime check (thin client prototype): the signals curl can't observe — that only a
    titles map refetches on i18n.changeLanguage, map-source re-parse cost, client
    derivation cost, per-drawer latency. Drive pnpm dev (:5173) with the Playwright MCP
    against local :3000 (SahajCloud is cors: '*', so the browser reaches it; if the
    custom /events/geojson handler lacks a CORS header, add it — small backend fix).

This measurement does not depend on sydevs/SahajCloud#556. The slug migration doesn't
change payload weights or the split choice, so run the spike against the current local
backend. #556 matters only when implementing the winner (reading countryCode from the
migrated slug); that correctness check + the node unit lane (pnpm test:run) + a browser
pass belong to the follow-up build, not the measurement.

Files affected (investigation)

  • src/config/api/fetch.ts — add wholesale getRegions; getCountries/getRegion derive from cache; drop getRegionDoc/getChildRegions/countryCodeOf; event-data selects + keys per the chosen split
  • src/config/query-client.ts + query keys — locale on locale-dependent keys; per-class stale times
  • src/lib/shape/hierarchy.ts — region-tree derivation helpers
  • src/types/region.ts, src/types/event.ts — schemas for the wholesale regions list + the chosen event-data shape
  • src/mocks/ — fixtures

References

Activity

  1. changed the title [-]perf(api): spike — populate hierarchy views from cached feed[/-] [+]perf(api): spike — split feed, regions, and titles by locale[/+] on Jul 10, 2026
  2. changed the title [-]perf(api): spike — split feed, regions, and titles by locale[/-] [+]perf(api): spike — separate region hierarchy from the event feed[/+] on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions