Skip to content

Honor {fetch: false} in dataPool.getDaily (#1087) - #1088

Open
gangster wants to merge 1 commit into
shift-org:mainfrom
gangster:issue-1087-favorites-cache-only-fetch
Open

Honor {fetch: false} in dataPool.getDaily (#1087)#1088
gangster wants to merge 1 commit into
shift-org:mainfrom
gangster:issue-1087-favorites-cache-only-fetch

Conversation

@gangster

@gangster gangster commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #1087.

favorites.js passes {fetch: false} to dataPool.getDaily to read from the in-memory cache only, but the guard tested === false, so it ran the fetch in exactly the case it was asked not to:

-    } else if (!options || options.fetch === false) {
+    } else if (!options || options.fetch !== false) {

Because that call sits inside an awaited for loop over every stored key, the result was one serialised events.php request per favorite, every time the Favorites tab was opened.

Verification

Favorited 4 rides through the UI, then loaded /events/favorites fresh so the in-memory caldaily_map started empty (an in-session cache hit masks the bug), with fetch instrumented to record every API call.

before after
events.php?id= requests 4 0
favorites rendered 4 4
wall time for those requests 17.3 ms

Before: ?id=6, ?id=1, ?id=2, ?id=8 taking 11, 2.1, 1.9 and 1.9 ms, starting at +0, +11.3, +13.5 and +15.5 ms. Each start lines up with the previous request finishing, confirming they were serialised rather than just issued in quick succession.

After: no requests, and all four favorites still render with the correct titles, dates and times from local storage — 4 stored keys producing 4 cards across 4 distinct dates, including two occurrences of the same series.

What this changes

Worth stating plainly, since it is the one judgement call in here: those requests were not doing nothing. updateStorage runs the response back through pick(), so the fetch could never add a field the stored copy lacked, but it did refresh values — a ride cancelled or retimed after being favorited was picked up on the next visit. After this change a favorite shows what it showed when it was saved, until you open it.

That reads as the intended design rather than a regression:

  • pick()'s comment: "doesn't store newsflash: there's no fast refresh; it might be stale."
  • The comment at the call site describes a background refresh as future work.
  • docs/CalVue.md still lists "a disclaimer about opening each favorite to see the latest information" and "future: server helper to quick update favorite status" as open items.

If you would rather keep refreshing, this fix is still the right starting point — the refresh then wants to become deliberate and batched, instead of one awaited request per favorite on the critical path.

Also worth knowing

getDaily(id, {fetch: true}) previously matched neither branch and returned undefined. Nothing calls it that way, so it was latent; this change makes it behave as the name suggests.

No tests here — there is no frontend test harness in the repo. Verified manually as described above; npm test (backend) is unchanged at 53/53.

The Favorites tab passes {fetch: false} to getDaily, intending to read
from the in-memory cache only, but the guard tested for === false and
so ran the fetch in exactly the case it was asked not to. Because the
call sits inside an awaited for loop over every stored favorite, that
produced one serialised events.php request per favorite on each visit.

Inverting the comparison makes a cache miss return undefined, which
favorites.js already handles: the stored copy is left alone and the
list renders from local storage.

Note this also removes the incidental refresh those requests were
doing. Responses are filtered through pick() either way, so no field
is lost, but values saved alongside a favorite are no longer updated
in the background. That matches the documented intent: pick() notes
the data "might be stale", and CalVue.md still lists a refresh helper
and a staleness disclaimer as open items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Favorites page fetches every favorite because getDaily's guard is inverted

1 participant