From 670ecc01623e2f5cef1eda809fe615186d5232fe Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 10:42:48 +0100 Subject: [PATCH] Judge fetched tiles apart from kept ones; share Esri's request slots Review round 2: with part of a map's tiles on disk, the placeholder check saw several pictures and let a provider's placeholder through, drew it and kept it for 30 days. The tiles fetched now are judged on their own: two or more that are all one picture matching no kept tile are a placeholder, and the map fails whole (nothing drawn or kept, the poster served for five minutes). A real uniform tile, such as open sea, matches one kept before and passes. From its notes: the request slots are per tile host, so the satellite and both grey canvases share Esri's six; a weak If-None-Match matches; the README says a poster is kept once its map or photo came. Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh --- README.md | 2 +- cdn-api.py | 2 +- posters_service.py | 33 ++++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d8afe5f..e1bb715 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ rate limit and kept in `cache/jolpica/`; a throttled or failed fetch is said in Everything the service fetches or renders is kept in `cache/` (the module's cache volume): race schedules from Jolpica in `cache/jolpica/` (a season that is over for good, the running one for six hours), map tiles in -`cache/tiles/` (30 days), and every poster and thumbnail in `cache/posters/` once it rendered whole. A poster is +`cache/tiles/` (30 days), and every poster and thumbnail in `cache/posters/` once its map or photo came. A poster is sent with an `ETag` and a day's `Cache-Control`; one whose map or photo failed is not kept, and is sent with five minutes', so it is rendered again once its source answers. diff --git a/cdn-api.py b/cdn-api.py index fbf6a93..668d219 100644 --- a/cdn-api.py +++ b/cdn-api.py @@ -108,7 +108,7 @@ def poster_response(request: Request, png: bytes, kept: bool) -> Response: return FastAPIResponse(content=png, media_type="image/png", headers={"Cache-Control": "public, max-age=300"}) etag = '"' + hashlib.sha256(png).hexdigest()[:32] + '"' headers = {"Cache-Control": "public, max-age=86400", "ETag": etag} - if etag in [tag.strip() for tag in request.headers.get("if-none-match", "").split(",")]: + if etag in [tag.strip().removeprefix("W/") for tag in request.headers.get("if-none-match", "").split(",")]: return Response(status_code=304, headers=headers) return FastAPIResponse(content=png, media_type="image/png", headers=headers) diff --git a/posters_service.py b/posters_service.py index e6b853b..950579a 100644 --- a/posters_service.py +++ b/posters_service.py @@ -20,6 +20,7 @@ import math import os import threading import time +import urllib.parse import urllib.request from concurrent.futures import ThreadPoolExecutor from enum import Enum @@ -80,8 +81,14 @@ TILE_PROVIDERS = { # Tiles are kept on disk under cache/tiles/