BUILD147 — обновление турнирной таблицы

This commit is contained in:
2026-09-18 18:46:36 +03:00
parent baca1e083c
commit a25c633a0b
4 changed files with 86 additions and 11 deletions

View File

@@ -2307,10 +2307,11 @@ class HockeyDataService:
endpoint: str,
*,
cache_seconds: float,
force: bool = False,
) -> Any:
now = time.monotonic()
cached = self._resource_response_cache.get(endpoint)
if cached and now - cached[0] < max(0.0, cache_seconds):
if not force and cached and now - cached[0] < max(0.0, cache_seconds):
return cached[1]
response = await self.client.fetch_xml(endpoint)
self._resource_response_cache[endpoint] = (now, response)
@@ -5030,6 +5031,7 @@ class HockeyDataService:
*,
language: str = "ru",
game_external_id: str = "",
force: bool = False,
) -> dict[str, Any]:
settings = self.settings.public()
endpoint = self._resolve_match_resource_endpoint(
@@ -5040,6 +5042,7 @@ class HockeyDataService:
response = await self._fetch_cached_resource(
endpoint,
cache_seconds=float(settings["standings_cache_seconds"]),
force=force,
)
parsed = parse_standings_xml(response.content, language=language)
source_tournament_id = str(parsed.get("tournament_id") or "")

View File

@@ -1262,11 +1262,11 @@
}));
}
function standingsUrl({ sync = false } = {}) {
function standingsUrl({ sync = false, force = false } = {}) {
const params = new URLSearchParams({ language: state.language });
if (state.selectedGameId) params.set("game_id", state.selectedGameId);
return `/api/hockey/tournaments/${encodeURIComponent(state.selectedId)}/standings`
+ `${sync ? "/sync" : ""}?${params.toString()}`;
const suffix = force ? "/force-sync" : (sync ? "/sync" : "");
return `/api/hockey/tournaments/${encodeURIComponent(state.selectedId)}/standings${suffix}?${params.toString()}`;
}
function applyStandingsData() {
@@ -1275,26 +1275,37 @@
});
}
async function loadTournamentStandings({ sync = false } = {}) {
if (!state.selectedId) return;
async function loadTournamentStandings({ sync = false, force = false } = {}) {
if (!state.selectedId) return null;
try {
const shouldPost = Boolean(sync || force);
const loaded = await request(
standingsUrl({ sync }),
sync ? { method: "POST", timeoutMs: 30000 } : {}
standingsUrl({ sync, force }),
shouldPost ? { method: "POST", timeoutMs: 30000 } : {}
);
state.standings = loaded.standings || loaded;
applyStandingsData();
return loaded;
} catch (error) {
if (sync) {
if (sync || force) {
try {
const cached = await request(standingsUrl({ sync: false }));
const cached = await request(standingsUrl({ sync: false, force: false }));
state.standings = cached.standings || cached;
applyStandingsData();
} catch (_) {}
}
if (force) throw error;
return null;
}
}
async function refreshTournamentStandings() {
if (!state.selectedId) {
throw new Error(state.language === "en" ? "Tournament is not selected" : "Турнир не выбран");
}
return loadTournamentStandings({ sync: true, force: true });
}
function tournamentStatisticsUrl({ sync = false, force = false } = {}) {
const params = new URLSearchParams({ language: state.language });
if (force) params.set("force", "true");
@@ -2699,6 +2710,7 @@ document.addEventListener("visibilitychange", () => {
selectTournament: openTournament,
selectGame: openGame,
reloadGames: () => loadGames({ autoSync: false }),
refreshStandings: refreshTournamentStandings,
};
function installGlobalTooltipPortal() {