Skip to content

The whole atlas loads, and keeps loading as it grows #256

Closed
3 of 3 issues completed
Closed

Description

@Ardnived

The goal

Every visitor sees the whole atlas — every country, every place, every class — and it keeps loading at today's speed as the atlas grows. The atlas is small enough today that this works. The goal is that it keeps working once there are many more classes, and once the system behind the atlas stops allowing it to ask for all of the data in one request.

Why it matters

The atlas runs inside other people's websites, which we do not deploy. If it ever loads only part of the data, nothing on screen says so: a visitor in a city with twelve classes would see none, and conclude there are none. We have already decided to stop letting the atlas ask for everything in one request — and asking for everything in one request is the only way it reads data today. So the atlas has to learn to read the data in pieces before that restriction arrives, or it quietly goes half-empty everywhere at once.

What success looks like

  • The map shows every class, and the place list shows every country that has one. Today that is 452 classes and 25 countries.
  • Opening the largest country shows all of its classes. Today that is Brazil, with 81.
  • If the atlas cannot be loaded in full, the visitor sees a clear message with a way to try again — never a map that looks complete but is not.
  • On a first visit, the map's pins appear within 5 seconds. On a repeat visit within five minutes, within 2 seconds.
  • After the restriction above goes live, the two counts in the first line still match, checked on a real client site.

Not included

  • Changing what the map shows. This goal is about loading it.
  • Fetching only one region's data instead of the whole atlas. Downloading the whole atlas once is what makes every region equally fast and lets one download serve many visitors. Changing that is much larger, separate work.
  • Making the atlas faster than it is today. This goal protects today's speed as the atlas grows. It does not promise an improvement.

Decisions

  • May the atlas ask for a whole set of data in one request? → No. It must read the data in pieces, and that change must be live before the restriction ships. (Ardnived, 2026-10-06, on fix(api): unbounded client limit and page reach SQL and return 500 SahajCloud#887)
  • How much may one request ask for? → 2,000 rows. Today's 646 places and 452 classes each fit in a single request, so this costs nothing until the atlas is roughly four times its present size. (Ardnived, 2026-10-06)
  • What does this goal promise — that the atlas is never shown incomplete, or that it gets faster? → Close this goal. Its work is written up as refactor(api): paginate the three pagination: false SahajCloud reads #253 (merged) and feat(api): refuse an unbounded client read, once the Atlas widget paginates SahajCloud#889, and the answers below are carried there. (Ardnived, 2026-10-21)
  • If the atlas cannot be loaded in full, what should a visitor see? → A clear error, with a way to try again. Nobody is told a city has no classes when it has twelve. (Ardnived, 2026-10-21)
  • How much growth should this be built to survive? → Today's size plus about four times headroom, as the 2,000-row page already gives. Revisit if bulk importing (Managers can import a whole region's classes at once #258) multiplies the classes. (Ardnived, 2026-10-21)
  • Should the restriction be announced for one release before it is enforced? → No. Enforce it straight away: a refused request gets a clear error naming the limit, and every refusal is recorded where we already watch. (Ardnived, 2026-10-21)

Open questions

None.

Notes

Related: #253, sydevs/SahajCloud#887, sydevs/SahajCloud#889

Measured in production on 2026-10-08: 452 classes, 646 places, 25 of 34 countries have at least one class, largest country Brazil with 81. Nothing is slow or failing today because a region is large. The technical findings, the measurements and the order the pieces must ship in are in the notes comment on this ticket.

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added this to the Sahaj Atlas launch milestone on Oct 8, 2026
  2. added theissue type on Oct 8, 2026
  3. added
    bot:working
    on Oct 8, 2026
  4. sydevs-bot commented on Oct 8, 2026

    @sydevs-bot
    Contributor

    🤖 no session running

    recent dispatches
    • 01:22Z revise-roadmap · attempt 1 · session · done
    • 01:22Z revise-roadmap · attempt 1 · session

    Written by the sydevs dispatcher. Sessions never edit this comment.

  5. changed the title [-]Large regions load reliably[/-] [+]The whole atlas loads, and keeps loading as it grows[/+] on Oct 8, 2026
  6. sydevs-bot commented on Oct 8, 2026

    @sydevs-bot
    Contributor

    Technical notes

    Intake review, 2026-10-08. Three lenses plus read-only production measurement. Edited in place on later runs — not a conversation.

    What exists today

    There is no region-scoped read. grep -n "where:" src/config/api/fetch.ts returns nothing. The widget makes exactly three global reads at boot, all pagination: false:

    Read fetch.ts Gets
    getRegions :172-182 every region, every level
    getGeojson → GET /events/geojson :208-216 every not-finished event
    getEventTitles :242-246 every event title, per locale

    Every region view is derived from those three cached objects in memory — getRegion (:420-426), getCountries (:390), getEvents (:540), getCalendarEvents (:574) issue zero requests of their own (indexedFeed, countUnder, boundsUnder, partitionUnder in src/lib/shape). So opening Brazil and opening a one-class city cost identical requests and identical bytes. The recorded position behind this is docs/rules/data-layer.md:104 — "Treat paging as a render budget, not a network one."

    The feed is also edge-cached: cache-control: public, max-age=300, s-maxage=300, vary: Authorization, Cache-Tag: events,regions with purge-on-write (SahajCloud src/plugins/cache/). Unmentioned by #253, SahajCloud#887 and SahajCloud#889. Any new feed shape must keep it.

    Measured in production, 2026-10-08

    Read-only GET https://cloud.sydevelopers.com/api/... with the routine's SAHAJCLOUD_API_KEY. This settles the open question #253 and SahajCloud#889 both carry.

    Read totalDocs On the wire (gzip)
    regions 646 ~21 KB
    events (titles) 452 ~8 KB
    GET /events/geojson 452 features ~58 KB

    Hierarchy: 34 country, 100 region, 460 city, 52 venue. 25 of the 34 countries have at least one class (CountriesView hides the empty nine). Largest country Brazil 81, then United Kingdom 48, Australia 46, France 35, Canada 34. Largest region South East (GB) 25; largest city London 18. All 452 events resolve to a country — no orphans.

    Cold vs warm, measured: geojson 2.12 s cold (cf-cache-status: MISS) against 0.18 s warm; regions 0.48 s / 0.16 s; titles 0.34 s / 0.33 s. ~87 KB compressed for all three.

    Consequence: at MAX_CLIENT_LIMIT = 2000, #253's page loop fetches exactly one page per read. Zero extra requests, zero latency change, no user-visible improvement. The corpus must grow ~3.1× (regions) or ~4.4× (events) before a second page is ever fetched. #253 is a compatibility change, not a performance change.

    Neither cap exists in production yet — limit=2000 and a 646-row limit=0 both return 200. SahajCloud PR #890 is open, unmerged, mergeable_state: blocked, review requested from Ardnived.

    ⚠ pagination=false with an explicit limit reports pagination metadata that lies

    Verified against production twice, on regions:

    ?pagination=false&limit=100  →  docs 100  totalDocs 100  totalPages 1  hasNextPage false
    ?limit=100                   →  docs 100  totalDocs 646  totalPages 7  hasNextPage true
    

    With pagination off, the envelope reports totalDocs equal to the page size and hasNextPage: false. A page loop using that shape would be told, forever, that it already has the whole atlas — the silent-partial-atlas failure, reached by the shape that looks safest.

    This matters to two open tickets and is recorded on neither:

    • refactor(api): paginate the three pagination: false SahajCloud reads #253 must send pagination on and pay the per-page COUNT. Its own note that pagination: false skips the COUNT reads as an invitation to keep it off.
    • SahajCloud#889's acceptance criterion "a client read sending pagination=false with a non-zero limit is unaffected" blesses exactly this shape. It is defensible for SahajCloud's own internal reads, which never page — but it must not be the shape the widget adopts, and the trap belongs in that ticket's body.

    ⚠ The second blocker, and a cost nobody has written down

    SahajCloud#889 already records that #253 alone does not unblock the refusal: loadRegionTree (SahajCloud src/lib/atlas/regionTree.ts:122-137) is itself a whole-table regions read with pagination: false, on the caller's own req, triggered by the virtual webPath/webUrl fields. FEED_SELECT selects webPath (fetch.ts:119) and REGIONS_SELECT selects webPath + webUrl (:138-139), so the widget triggers it on every feed read. Fix is asTrustedReq(req) at three sites, inside SahajCloud.

    The cost consequence is not recorded anywhere. That read is memoised per request (regionTree.ts:171, memoizeOnRequest). So splitting the feed into N pages means N whole-table region scans server-side where there is one today. A goal whose first line is about loading should not be approved over a change that multiplies the server's work by the page count. It does not bind at one page, but it is the reason a precomputed feed (below) is the better server-side answer if the corpus grows.

    Build vs buy, weighed

    • TanStack Query infiniteQuery (already a dependency, @tanstack/[email protected]): gives the bounded walk and early break for free, but the walk is strictly sequential, and the cache entry becomes InfiniteData<T>. ['geojson'] has six direct call sites (Map.tsx:254, SearchFilters.tsx:177, use-country-site.ts:42, FilterView.tsx:49, CountriesView.tsx:53, views/shared.tsx:424) that all consume Geojson. No — but steal its pages-with-early-break semantics as the cap's shape.
    • @payloadcms/sdk / Payload core: no findAll, and pagination.maxLimit does not exist in [email protected] (established on SahajCloud#887). Nothing to buy.
    • A pagination package: [email protected] wraps raw fetch and reads Link headers — cannot wrap sdk.find, and SahajCloud returns pagination as JSON foreign members. payload-rest-client is a competing SDK, last published 2025-02. Build the ~20-line loop, as refactor(api): paginate the three pagination: false SahajCloud reads #253 specifies.
    • Mapbox clustering: already in use (Map.tsx:473-483, cluster: true). Load-bearing detail: Map.tsx:326-339 filters in JS before clustering so bubble counts match the list. Nothing to do, and a layer-level filter would break that.
    • Mapbox vector tiles / MTS: the only true viewport-scoped option, and it dismantles the derived-client-side design — countUnder, boundsUnder, the uncapped distance ranking (feat(widget): instrument event surfaces + evaluate TelemetryDeck #51), calendar expansion and buildRegionMatcher all read the whole feed, and matchesFilters reads recurrence against today's date, which is not expressible as a Mapbox filter. Plus a publish pipeline and loss of the Cache-Tag purge path. No — recorded so it is not re-proposed.
    • Region-scoped reads: GET /events/geojson already forwards where (SahajCloud .../geojson.ts:93-104), so the fetch needs no server change. What blocks it is the aggregates: per-region counts and bounding boxes are derived from the global feed, and SahajCloud has no count or aggregate endpoint. This is the named successor if growth demands it, not this goal.
    • A precomputed feed endpoint (GET /api/atlas/feed, rebuilt on write, same purge tag): the best server-side lever if one is ever needed — one cheap bounded request, and it retires the virtual-field cost above. Hold; no measurement says the cold read is a problem.
    • Payload /count per region: 595+ requests. No.

    Risks

    • The widget's failure mode is two things on one screen: the map renders blank and silent (Map.tsx:252 uses useQuery, and {filtered && <Source>} at :472-483 gates the layer), while the drawer shows the error panel (CountriesView.tsx:37 is useSuspenseQuery → boundary at App.tsx:89 → classifyError 5xx → server → "Our servers are having trouble right now." with Try again and Report, Fallbacks.tsx:191-201). So "broken or empty map" was accurate, for a reason unrelated to region size.
    • No request timeout anywhere. grep -rn "AbortSignal\|AbortController\|signal:\|timeout" src/config/api/ src/config/query-client.ts returns nothing. With MAX_QUERY_RETRIES = 1 the spinner window on a slow-but-not-down origin is two full origin waits. Unmeasured — settling it needs a deliberately stalled origin against a preview, not production. This is the one fact this run could not settle.
    • Rate limiting is not the binding constraint: 500 requests / 60 s per (client, IP) at the edge, against ~6 requests for a cold boot.
    • No contract changes. cloud.sydevelopers.com is already in docs/embedding.md's connect-src (:794), EventFeatureCollection already types the pagination members (src/types/payload/response-types.ts:39-51), and nothing is host-observable — so no CHANGELOG.md entry and no docs/embedding.md edit.

    Children, and the order they must ship in

    Three sub-issues are attached: #253 (Task, Priority High — the widget-side child, implementation-ready apart from the pagination-on correction above), sydevs/SahajCloud#889 (Feature, blocked — the refusal plus the three internal reads #253 cannot reach), and sydevs/SahajCloud#887 (Bug, with PR #890 open).

    ⚠ Two cautions on that set. #887's 500 comes from a hand-crafted out-of-range limit/page, a shape the widget never sends, so counting it as part of this goal overstates what region size has to do with it. And #253 is High while this goal is Medium: its deadline is API compatibility with a breaking change shipping to a widget on host domains we do not deploy, which is not a performance concern.

    Rollout order, from SahajCloud#889 — not optional, and step 3 is SahajCloud's:

    1. PR #890 merges.
    2. refactor(api): paginate the three pagination: false SahajCloud reads #253 merges and deploys.
    3. The three internal pagination: false reads get asTrustedReq.
    4. The refusal ships.

    This run attached nothing and requested no replan. The children were attached outside it, between two reads of the ticket. No replan was asked for because open question 1 may close or re-aim this goal, and planning against a shape still in question would churn three tickets, two of them in another repo. Answer the questions first.

    Where the lenses disagreed

    Scope modelled 653 events / 595 regions from the committed seed extract (SahajCloud seeds/atlas/data/); the production measurement above says 452 events / 646 regions. Production holds — the seed is a 2026-08 legacy extract, and a client read is filtered to published and not-finished, which is exactly what a visitor sees. Regions have grown past the seed; events read lower because of that filtering. The conclusion is unchanged either way: both numbers sit far under 2000.

    Sketch of a split, if question 1 answers A

    The three children already cover the mechanical work. The only piece not covered by an open ticket is the never-silently-partial guarantee, and it needs a child of its own only if question 2 answers A and the current behaviour does not already satisfy it.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  7. sydevs-bot commented on Oct 8, 2026

    @sydevs-bot
    Contributor

    Reviewed from the code and measured against production. The premise does not hold: there is no region-scoped request. The widget fetches the whole atlas once and derives every region from it in memory, so a large region and a one-class city cost identical requests. All three original success lines were unverifiable.

    Settled the row count #253 and sydevs/SahajCloud#889 both have open: 452 classes, 646 places, largest country Brazil with 81. Each read fits one page of the agreed 2,000, so that work adds zero requests. It is a compatibility change, not a performance one.

    Retitled, and rewrote the body around the real risk: never showing a half-empty atlas once whole-table reads are refused. Your 2026-10-06 decision is recorded under ## Decisions. Measurements, two hazards neither ticket records, and the rollout order are in the notes comment.

    Three decisions need you — see ## Open questions. Reply @sydevs-bot revise 1A 2A 3A, or in your own words.

    Then @sydevs-bot implement plans the implementation tickets.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  8. added and removed
    bot:working
    on Oct 8, 2026
  9. sydevs-bot commented on Oct 11, 2026

    @sydevs-bot
    Contributor

    A page walk is not immune to the matching set changing between pages. Found while implementing #253, recorded here because it only bites past one page.

    #253's walk reads page 1, then pages 2…N by OFFSET. walkSort gives the order a unique tiebreaker, which fixes ties, not mutation. Above 2000 rows:

    • An event crossing schedule.lastDate between two page reads shifts the offset, and one event vanishes from the feed.
    • A publish in the same gap repeats a row, and the region then counts one extra event.

    Neither raises an error. Keyset paging (where[id][greater_than]) is immune and suits the two id-sorted reads, but it is sequential, and getRegions cannot use it while it sorts by name for display.

    At 646 regions and 452 events the second page never executes, so nothing is wrong today. It becomes real at roughly 4× growth, which is this goal's subject.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  10. sydevs-bot commented on Oct 11, 2026

    @sydevs-bot
    Contributor

    A decision came up while working on sydevs/SahajCloud#889. It is in Open questions above, with options and a recommendation.

    🤖 sydevs dispatcher

  11. Ardnived commented on Oct 21, 2026

    @Ardnived
    ContributorAuthor

    Answered in the terminal by @Ardnived:

    Closing this goal: its work is #253 (merged) and sydevs/SahajCloud#889, which now carries these answers.

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

    Fields

    Priority

    Medium

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions