fix(catalog): read furnidata from one cache, purge the gamedata edge on write
Gitea Actions Runner Test / test-job (push) Successful in 1s
CI / check (push) Successful in 36s
CI / tests-integration (push) Successful in 1m52s
CI / tests-unit (push) Successful in 1m56s
CI / tests-ui (push) Successful in 2m48s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 2m27s

Furniture was not always loading completely because the same file was cached
twice and nobody could reach the client.

The catalog items loader kept its own 30s TTL copy of FurnitureData.json next
to the mtime-validated cache in `furni-data.ts`. An import cleared only the
second one, so the catalog table kept serving pre-import furnidata — empty
descriptions and revisions — until the TTL ran out. The loader now reads
through `readFurniData`, which revalidates on mtime+size and is reset by
every write, so there is exactly one cache and it cannot go stale on its own.
`invalidateFurniDataCache` and its single call site are gone with it.

The client was worse: nginx served all of /gamedata/ with `max-age=604800`,
and the `cms-gamedata` purge that would have fixed it hung off the catalog Git
export, which is disabled in production. A freshly imported item was invisible
in the client for up to seven days no matter how often you imported.

- `writeFurniData` now purges the gamedata edge tag itself. One place covers
  import, batch, resync, regen, nitro-editor, translate and dedupe. It is
  fire-and-forget and swallowed at every level: a stale edge copy is bounded
  by the edge TTL, so a failed purge must never fail an import.
- nginx splits /gamedata/ by how mutable the content is: config/ gets
  `max-age=300, must-revalidate`, bundled/ `max-age=3600, must-revalidate`,
  and the content-addressed trees (c_images, album*, clothes) keep the long
  TTL. `must-revalidate` is the point — the client now revalidates instead of
  replaying the old body. All three keep `Cache-Tag: cms-gamedata` so the
  purge still reaches them.
- A 30-minute safety-net purge in the jobs worker covers the case where
  Cloudflare was unreachable at write time.
This commit is contained in:
openhands committed 2026-10-01 15:16:48 +02:00
1 parent cede541813
commit a6cc3cafa9
5 files changed
+125 -44

No files matched your search

+50
View File
@@ -233,6 +233,56 @@ server {
location = /gamedata { return 301 /gamedata/config/; }
location = /gamedata/ { return 301 /gamedata/config/; }
# ─── Gamedata: drie cache-klassen, want niet alles onder /gamedata/ is
# even veranderlijk.
#
# Dit pad had één regel voor de hele boom: `max-age=604800` (7 dagen). De
# Habbo-client haalt FurnitureData.json hier op, dus na een import bleef het
# client-side dagenlang de oude versie tonen — een nieuw geïmporteerd
# meubel was gewoon onzichtbaar. De purge van de `cms-gamedata`-tag
# (edge-cache.ts) raakt alleen de Cloudflare-kopie, niet de browser.
#
# 1. config/ — FurnitureData.json + de vertaalde bestanden. Verandert
# bij elke import. Kort, en `must-revalidate` sluit de
# "stuur uit de cache"-route uit zodat de client na de
# TTL een 304 vraagt in plaats van de oude body te hergebruiken.
# 2. bundled/ — nitro-bundles per sprite. De inhoud kan veranderen zonder
# dat de bestandsnaam verandert (schalen, repareren), dus
# ook revalideren, maar minder vaak: ze worden veel vaker
# opgehaald dan ze worden geschreven.
# 3. alles wat overblijft (c_images, album*, clothes, …) — content-addressed
# of per item uniek, nooit herschreven onder dezelfde naam. Blijft lang.
location ^~ /gamedata/config/ {
alias /var/www/Gamedata/config/;
add_header Cache-Control "public, max-age=300, must-revalidate";
access_log off;
add_header Cache-Tag "cms-gamedata";
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
if ($cors_headers) {
add_header Access-Control-Max-Age 1728000;
add_header Content-Type "text/plain; charset=utf-8";
return 204;
}
}
location ^~ /gamedata/bundled/ {
alias /var/www/Gamedata/bundled/;
add_header Cache-Control "public, max-age=3600, must-revalidate";
access_log off;
add_header Cache-Tag "cms-gamedata";
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
if ($cors_headers) {
add_header Access-Control-Max-Age 1728000;
add_header Content-Type "text/plain; charset=utf-8";
return 204;
}
}
location /gamedata/ {
alias /var/www/Gamedata/;
add_header Cache-Control "public, max-age=604800";