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 f6b9f937d0 (Finished images: what clients keep, the address version)
Claude-Session: https://claude.ai/code/session_01JG73KFhbaNj3tyJ8tKmE3W
This commit is contained in:
@@ -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
|
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`.
|
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
|
(`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/<version> (+<its public address>)`. OpenStreetMap tiles
|
request the service makes carries the User-Agent `f1-circuits/<version> (+<its public address>)`. 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.
|
are fetched only when a picture asks for them, at most two at once; Wikimedia Commons is asked one request at a time.
|
||||||
|
|||||||
+3
-3
@@ -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,
|
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:
|
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
|
#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,
|
def render_poster(request: Request, kind: str, grand_prix_name: Optional[str] = None, season: Optional[int] = None,
|
||||||
session_slug: Optional[str] = None) -> Response:
|
session_slug: Optional[str] = None) -> Response:
|
||||||
"""A picture with its credits, its licence and what clients may keep of it.
|
"""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."""
|
ETag (a 304 while it is unchanged); a picture served without its map or photo five minutes, with no ETag."""
|
||||||
try:
|
try:
|
||||||
options = poster_options.parse_options(request.query_params.multi_items(), kind)
|
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
|
- uses Kometa's f1_season builder for round/episode names
|
||||||
- sets url_poster on the show (the season poster)
|
- 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
|
- 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=<render version>
|
from the session thumbnail route; every address carries ?v=<address version>
|
||||||
|
|
||||||
Kometa harmlessly skips shows / seasons that don't exist in the Plex
|
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.
|
library, so we can emit the full schedule and let Kometa do the matching.
|
||||||
|
|||||||
+7
-4
@@ -8,9 +8,12 @@ import re
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Iterable, Optional
|
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.
|
# picture made before is served again. r3: licensed sources, kept layers, options and credits.
|
||||||
RENDER_VERSION = "r3"
|
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.
|
# A frame is the picture's own size: a poster (race and season) and a session thumbnail.
|
||||||
FRAMES = {"poster": (1000, 1500), "thumb": (1920, 1080)}
|
FRAMES = {"poster": (1000, 1500), "thumb": (1920, 1080)}
|
||||||
@@ -69,7 +72,7 @@ class Options:
|
|||||||
accent: str
|
accent: str
|
||||||
width: int
|
width: int
|
||||||
format: str
|
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:
|
def canonical(self) -> str:
|
||||||
"""The options as they are drawn, the style resolved: two addresses that draw the same picture match."""
|
"""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))
|
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,
|
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
|
# ------------------------------------------------------------------ keys
|
||||||
@@ -194,7 +197,7 @@ def finished_key(route: str, options: Options, layer_keys: Iterable[str]) -> str
|
|||||||
# ------------------------------------------------------------------ what clients keep
|
# ------------------------------------------------------------------ what clients keep
|
||||||
|
|
||||||
def cache_headers(kept: bool, versioned: bool, etag: str) -> dict[str, str]:
|
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."""
|
a picture served without its layer five minutes, with no ETag."""
|
||||||
if not kept:
|
if not kept:
|
||||||
return {"Cache-Control": "public, max-age=300"}
|
return {"Cache-Control": "public, max-age=300"}
|
||||||
|
|||||||
+3
-3
@@ -919,12 +919,12 @@ class PostersService:
|
|||||||
def render_kometa_metadata(self, first_season: int = 1950, last_offset: int = 1) -> str:
|
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
|
"""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
|
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
|
round): its race poster; per episode: its session thumbnail. Every poster address carries the address
|
||||||
version, so clients keep it for good and a changed look reaches them under a new address."""
|
version (?v=), so clients keep it for good and a changed look reaches them under a new address."""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
version = f"?v={po.RENDER_VERSION}"
|
version = f"?v={po.ADDRESS_VERSION}"
|
||||||
last_season = datetime.utcnow().year + last_offset
|
last_season = datetime.utcnow().year + last_offset
|
||||||
lines: list[str] = [
|
lines: list[str] = [
|
||||||
"# This file's data (race names, rounds, dates) comes from the Jolpica F1 API "
|
"# This file's data (race names, rounds, dates) comes from the Jolpica F1 API "
|
||||||
|
|||||||
@@ -183,7 +183,10 @@ class OptionsTest(unittest.TestCase):
|
|||||||
# Any option given overrides the style; equal pictures share one canonical form, whatever their address
|
# 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("style=minimal&checker=on").checker, True)
|
||||||
self.assertEqual(self.parse("bg=aerial&v=r1").canonical(), self.parse("").canonical())
|
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)
|
self.assertFalse(self.parse("v=r2").versioned)
|
||||||
|
|
||||||
def test_an_unknown_option_or_value_is_named(self):
|
def test_an_unknown_option_or_value_is_named(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user