Cache walk-on NR fares by day of week for instant display
Store GWR walk-on fares keyed by timetable period + weekday
(weekday_gwr_fares_{direction}_{crs}_{period}_{day}), mirroring
the existing NR timetable weekday cache strategy.
On page load the server embeds any cached weekday fares in the page
as WALKON_CACHED_FARES so JS can populate prices immediately without
waiting for the GWR API. The live API call still runs afterwards to
verify and update any changed fares; the spinner label changes to
"Verifying fares" when cached prices are already shown.
The weekday cache is written whenever exact-date fares are fetched
from GWR, keeping it fresh, and populated lazily from the exact-date
cache on first access.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1bc7631863
commit
5f0d2c71b1
2 changed files with 28 additions and 0 deletions
|
|
@ -142,6 +142,7 @@
|
|||
const DEFAULT_MIN_CONN_IN = {{ default_inbound_min_connection }};
|
||||
let TRIP_FARES = {{ trip_fares_json | safe }};
|
||||
let ADVANCE_FARES = {{ advance_fares_json | safe }};
|
||||
const WALKON_CACHED_FARES = {{ walkon_cached_fares_json | safe }};
|
||||
let WALKON_API_URLS = {{ walkon_api_urls_json | safe }};
|
||||
let ADVANCE_API_URLS = {{ advance_api_urls_json | safe }};
|
||||
let ADVANCE_STREAM_URLS = {{ advance_stream_urls_json | safe }};
|
||||
|
|
@ -566,8 +567,17 @@
|
|||
return c === 'advance_std' || c === 'advance_1st';
|
||||
});
|
||||
if (needsAdvance) loadMissingAdvanceFares();
|
||||
/* Pre-populate walk-on fares from weekday cache so prices show immediately */
|
||||
var hasPreloaded = false;
|
||||
for (var sid in WALKON_CACHED_FARES) {
|
||||
if (WALKON_CACHED_FARES[sid]) { mergeWalkonFares(sid, WALKON_CACHED_FARES[sid]); hasPreloaded = true; }
|
||||
}
|
||||
updateDisplay();
|
||||
updateRowHighlights();
|
||||
if (hasPreloaded) {
|
||||
var loadingEl = document.getElementById('walkon-loading');
|
||||
if (loadingEl) loadingEl.innerHTML = '<span class="spinner spinner-inline" aria-hidden="true"></span>Verifying fares';
|
||||
}
|
||||
loadWalkonFares();
|
||||
startTimetableRefresh();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue