From db968ab31852e340df364a5c77b3dc53f86d14b5 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Sun, 17 May 2026 12:30:19 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20optimize=20SSR=20cache=20de?= =?UTF-8?q?pendencies=20and=20improve=20API=20query=20precision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .agents/skills/tibi-ssr-caching/SKILL.md | 9 +++++++++ frontend/src/App.svelte | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.agents/skills/tibi-ssr-caching/SKILL.md b/.agents/skills/tibi-ssr-caching/SKILL.md index 88f0237..a28ad36 100644 --- a/.agents/skills/tibi-ssr-caching/SKILL.md +++ b/.agents/skills/tibi-ssr-caching/SKILL.md @@ -78,6 +78,15 @@ When content changes, `clear_cache.js` only invalidates SSR entries that depend - `col:id` OR `col:*` on `PUT`/`DELETE` - everything on manual clear (`POST /ssr?clear=1` with no collection context) + +## Limit: 1 ensures precise dependencies + +By default, an API query for a collection (like `/api/v1/_/content?filter=...`) sets a list dependency `collection:*`. This means *any* change to ANY entry in that collection will clear the SSR cache for this page. + +If you are querying a single document (like a page or article based on its path or slug), you should ALWAYS append `limit: 1` to your API call (or pass `limit=1` to `getDBEntries`). + +When `api/hooks/lib/ssr-server.js` intercepts a request with `limit === 1` and exactly one result is returned, it will register a precise `collection:id` dependency instead of a wildcard `collection:*`. This optimizes the cache drastically, because edits to *other* pages won't invalidate this page. + ## How SSR data loading is supposed to work - Keep `frontend/src/ssr.ts` thin. It should set up locale state and call `render(App, { props: { url } })`. diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 9eb50e3..67eea26 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -162,7 +162,7 @@ "navigation", { type: "header", language: lang }, "sort", - undefined, + 1, undefined, undefined, undefined, @@ -172,7 +172,7 @@ "navigation", { type: "footer", language: lang }, "sort", - undefined, + 1, undefined, undefined, undefined,