From 25fee9ca85273a70da6c72cb9380e040a878d259 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 30 Nov 2026 10:51:49 +0100 Subject: [PATCH] Give the addresses an address version of their own, raised to a1 Every season poster changed with the joined picks, but the Kometa file kept handing out ?v=r3, an address clients keep for good: they would never load the new season posters. Raising the render version instead would draw every kept layer and finished picture again, though only the season posters changed. poster_options.ADDRESS_VERSION ("a1") sits beside RENDER_VERSION: the Kometa file writes it into every poster address, and only an address carrying it is sent the immutable Cache-Control; an address with ?v=r3 is now any other address (a day, then its ETag). Layers and finished pictures stay keyed by RENDER_VERSION, still r3, so nothing kept is drawn again except the season posters whose photo changed. The API's option text, the Kometa docstring and the README say "address version". The options test: ?v=a1 is kept for good, ?v=r3 no longer (on master it fails: no ADDRESS_VERSION, and ?v=r3 is still the immutable address). Builds: docs/posters.md at f6b9f937d09a3b79b2312af5bfd290c7408b20fb (Finished images: what clients keep, the address version) Claude-Session: https://claude.ai/code/session_01JG73KFhbaNj3tyJ8tKmE3W --- README.md | 2 +- cdn-api.py | 6 +++--- poster_options.py | 11 +++++++---- posters_service.py | 6 +++--- tests/test_posters.py | 5 ++++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ea5118a..5023c42 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ layers, at most 2 GB, the least recently used going first; a second season of a and fetches nothing. A picture whose map or photo did not arrive is served without it, kept nowhere, and sent with five minutes' `Cache-Control` and no `ETag`. -Clients keep an address that carries the render version (`?v=r3`, as the Kometa file writes it) for good +Clients keep an address that carries the address version (`?v=a1`, as the Kometa file writes it) for good (`immutable`); any other address a day, then ask again with its `ETag` and get a 304 while it is unchanged. Every request the service makes carries the User-Agent `f1-circuits/ (+)`. OpenStreetMap tiles are fetched only when a picture asks for them, at most two at once; Wikimedia Commons is asked one request at a time. diff --git a/cdn-api.py b/cdn-api.py index e9dd22e..3ea1e60 100644 --- a/cdn-api.py +++ b/cdn-api.py @@ -148,14 +148,14 @@ POSTER_OPTIONS_DOC = """Options are query parameters, the same on every poster r dark, light, none), `photo` (natural, bw), `show` (a comma list of wordmark, round, name, subtitle, date, circuit, locality, session), `locator` and `checker` (on, off), `track` (off, or #rrggbb with an optional width: #ffffff,6), `dim` (0 to 1), `accent` (#rrggbb), `width` (400 up to the frame's), `format` (png, jpg, webp), and - `v`, the render version, which the Kometa file adds so clients keep the picture for good.""" + `v`, the address version, which the Kometa file adds so clients keep the picture for good.""" def render_poster(request: Request, kind: str, grand_prix_name: Optional[str] = None, season: Optional[int] = None, session_slug: Optional[str] = None) -> Response: """A picture with its credits, its licence and what clients may keep of it. - An address with the current render version (?v=) is kept for good; any other a day, then asked again with its + An address with the current address version (?v=) is kept for good; any other a day, then asked again with its ETag (a 304 while it is unchanged); a picture served without its map or photo five minutes, with no ETag.""" try: options = poster_options.parse_options(request.query_params.multi_items(), kind) @@ -213,7 +213,7 @@ def get_kometa_metadata(): - uses Kometa's f1_season builder for round/episode names - sets url_poster on the show (the season poster) - sets url_poster on each Plex 'season' (== each F1 round) from the race poster route, and on each episode - from the session thumbnail route; every address carries ?v= + from the session thumbnail route; every address carries ?v=
Kometa harmlessly skips shows / seasons that don't exist in the Plex library, so we can emit the full schedule and let Kometa do the matching. diff --git a/poster_options.py b/poster_options.py index b1c5594..4cf11be 100644 --- a/poster_options.py +++ b/poster_options.py @@ -8,9 +8,12 @@ import re from dataclasses import dataclass from typing import Iterable, Optional -# Part of every layer's and every finished picture's key: raised when what a picture looks like changes, so no +# Part of every layer's and every finished picture's key: raised only when the drawing itself changes, so no # picture made before is served again. r3: licensed sources, kept layers, options and credits. RENDER_VERSION = "r3" +# Carried by the address clients are given (?v=), separate from RENDER_VERSION: raised when a look changes, so clients +# load the address again, served from the pictures already kept. a1: every season poster changed (the season photos). +ADDRESS_VERSION = "a1" # A frame is the picture's own size: a poster (race and season) and a session thumbnail. FRAMES = {"poster": (1000, 1500), "thumb": (1920, 1080)} @@ -69,7 +72,7 @@ class Options: accent: str width: int format: str - versioned: bool # the address carries the current render version (?v=) + versioned: bool # the address carries the current address version (?v=) def canonical(self) -> str: """The options as they are drawn, the style resolved: two addresses that draw the same picture match.""" @@ -157,7 +160,7 @@ def parse_options(items: Iterable[tuple[str, str]], kind: str) -> Options: fmt = _choice("format", given.get("format", "png"), tuple(FORMATS)) return Options(style=style, bg=bg, photo=photo, show=show, locator=locator, checker=checker, track=track, - dim=dim, accent=accent, width=width, format=fmt, versioned=given.get("v") == RENDER_VERSION) + dim=dim, accent=accent, width=width, format=fmt, versioned=given.get("v") == ADDRESS_VERSION) # ------------------------------------------------------------------ keys @@ -194,7 +197,7 @@ def finished_key(route: str, options: Options, layer_keys: Iterable[str]) -> str # ------------------------------------------------------------------ what clients keep def cache_headers(kept: bool, versioned: bool, etag: str) -> dict[str, str]: - """An address with the current render version is kept for good; any other a day, asked again with its ETag; + """An address with the current address version is kept for good; any other a day, asked again with its ETag; a picture served without its layer five minutes, with no ETag.""" if not kept: return {"Cache-Control": "public, max-age=300"} diff --git a/posters_service.py b/posters_service.py index cca7c73..a7859b6 100644 --- a/posters_service.py +++ b/posters_service.py @@ -919,12 +919,12 @@ class PostersService: def render_kometa_metadata(self, first_season: int = 1950, last_offset: int = 1) -> str: """The Kometa metadata YAML for the Formula 1 library, every season from `first_season` through current_year + last_offset. Per show: the f1_season builder and the season poster; per Plex season (a - round): its race poster; per episode: its session thumbnail. Every poster address carries the render - version, so clients keep it for good and a changed look reaches them under a new address.""" + round): its race poster; per episode: its session thumbnail. Every poster address carries the address + version (?v=), so clients keep it for good and a changed look reaches them under a new address.""" from datetime import datetime from urllib.parse import quote - version = f"?v={po.RENDER_VERSION}" + version = f"?v={po.ADDRESS_VERSION}" last_season = datetime.utcnow().year + last_offset lines: list[str] = [ "# This file's data (race names, rounds, dates) comes from the Jolpica F1 API " diff --git a/tests/test_posters.py b/tests/test_posters.py index c09848d..38ac28e 100644 --- a/tests/test_posters.py +++ b/tests/test_posters.py @@ -183,7 +183,10 @@ class OptionsTest(unittest.TestCase): # Any option given overrides the style; equal pictures share one canonical form, whatever their address self.assertEqual(self.parse("style=minimal&checker=on").checker, True) self.assertEqual(self.parse("bg=aerial&v=r1").canonical(), self.parse("").canonical()) - self.assertTrue(self.parse(f"v={po.RENDER_VERSION}").versioned) + # Kept for good: an address with the address version, never one with the render version it carried before + self.assertTrue(self.parse(f"v={po.ADDRESS_VERSION}").versioned) + self.assertNotEqual(po.ADDRESS_VERSION, po.RENDER_VERSION) + self.assertFalse(self.parse("v=r3").versioned) self.assertFalse(self.parse("v=r2").versioned) def test_an_unknown_option_or_value_is_named(self):