BUILD145
This commit is contained in:
@@ -1011,10 +1011,25 @@
|
||||
renderTournamentList();
|
||||
}
|
||||
if (state.selectedId) {
|
||||
// BUILD145: once per minute refresh the selected date at the source first.
|
||||
// The service also walks every game on that date and reconciles its score
|
||||
// from the per-game JSON card before PostgreSQL is read back into Runtime.
|
||||
if (!document.hidden && state.gameDate === localDateIso()) {
|
||||
try {
|
||||
await refreshSelectedTournamentScheduleCache();
|
||||
} catch (_) {}
|
||||
}
|
||||
if (state.view === "games") {
|
||||
state.games = await request(gamesUrl());
|
||||
applyGamesData();
|
||||
renderGames();
|
||||
} else {
|
||||
// Runtime may be on the Schedule tab while the drawer itself is closed.
|
||||
// Keep the selected-date payload current there as well.
|
||||
try {
|
||||
state.games = await request(gamesUrl());
|
||||
applyGamesData();
|
||||
} catch (_) {}
|
||||
}
|
||||
await loadTeamSchedule({ force: true });
|
||||
await loadTournamentStandings({ sync: false });
|
||||
@@ -1381,6 +1396,25 @@
|
||||
+ `&all_dates=true`;
|
||||
}
|
||||
|
||||
async function refreshSelectedTournamentScheduleCache({ forceDiscovery = false } = {}) {
|
||||
if (!state.selectedId || state.scheduleSyncBusy || operatorSettingsEditingActive()) return null;
|
||||
const configured = state.games?.meta?.credentials_configured
|
||||
?? state.navigation?.meta?.credentials_configured;
|
||||
if (configured === false) return null;
|
||||
state.scheduleSyncBusy = true;
|
||||
try {
|
||||
return await request(
|
||||
`/api/hockey/tournaments/${encodeURIComponent(state.selectedId)}/games/sync`
|
||||
+ `?on_date=${encodeURIComponent(state.gameDate)}`
|
||||
+ `&force_discovery=${forceDiscovery ? "true" : "false"}`
|
||||
+ `&lightweight=true`,
|
||||
{ method: "POST", timeoutMs: 30000 }
|
||||
);
|
||||
} finally {
|
||||
state.scheduleSyncBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
function applyTeamScheduleData() {
|
||||
const current = state.teamSchedule && typeof state.teamSchedule === "object"
|
||||
? state.teamSchedule
|
||||
@@ -1432,12 +1466,23 @@
|
||||
if (
|
||||
autoSync
|
||||
&& state.games.meta.credentials_configured
|
||||
&& !state.games.meta.schedule_loaded
|
||||
&& !state.gamesAutoSyncAttempted.has(syncKey)
|
||||
&& !state.scheduleSyncBusy
|
||||
) {
|
||||
// BUILD145: always do one quiet authoritative pass when a tournament is
|
||||
// opened, even when an old schedule cache already exists. The server
|
||||
// refreshes the XML and then reconciles every game on this date by JSON.
|
||||
state.gamesAutoSyncAttempted.add(syncKey);
|
||||
await syncGames(false, { silentSuccess: true });
|
||||
try {
|
||||
await refreshSelectedTournamentScheduleCache();
|
||||
state.games = await request(gamesUrl());
|
||||
applyGamesData();
|
||||
renderGames();
|
||||
await loadTeamSchedule({ force: true });
|
||||
} catch (_) {
|
||||
// Cached schedule remains usable if Stat2TV is temporarily unavailable.
|
||||
state.gamesAutoSyncAttempted.delete(syncKey);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
state.games = { meta: { date: state.gameDate, tournament_external_id: state.selectedId, count: 0 }, items: [] };
|
||||
@@ -1625,7 +1670,11 @@ function gameCard(game) {
|
||||
const fallbackLabel = result.fallback_used
|
||||
? (state.language === "en" ? " · tournament API fallback" : " · резервный API турнира")
|
||||
: "";
|
||||
notify(`${t("gamesLoaded")}: ${visibleCount} · ${result.endpoint}${fallbackLabel}`);
|
||||
const scores = result.score_reconcile || {};
|
||||
const scoreLabel = Number(scores.checked || 0)
|
||||
? ` · ${state.language === "en" ? "scores" : "счёт"} ${Number(scores.checked || 0) - Number(scores.failed || 0)}/${Number(scores.checked || 0)}`
|
||||
: "";
|
||||
notify(`${t("gamesLoaded")}: ${visibleCount} · ${result.endpoint}${fallbackLabel}${scoreLabel}`);
|
||||
}
|
||||
state.gamesAutoSyncAttempted.add(String(state.selectedId));
|
||||
state.games = await request(gamesUrl());
|
||||
|
||||
Reference in New Issue
Block a user