From b308471de201abb13b31ec8e6cbed867ec510bb9 Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sun, 3 May 2026 13:06:27 +0200 Subject: [PATCH] perf: persist unfurl cache between deploys via UNFURL_CACHE_DIR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CACHE_DIR in unfurl-shortcode.js and manifest path in eleventy.config.js now read UNFURL_CACHE_DIR env var (falls back to .cache/unfurl/ locally). deploy.yml sets UNFURL_CACHE_DIR=/usr/local/git/.cache/unfurl — same persistent runner volume used by OG_CACHE_DIR and sharp binary cache. Without this, every deploy re-fetched all 283 interaction URLs from scratch because .cache/ is gitignored and not preserved between builds. --- .github/workflows/deploy.yml | 1 + eleventy.config.js | 4 +++- lib/unfurl-shortcode.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 952ac08..bdbd4d9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -128,6 +128,7 @@ jobs: GITEA_INTERNAL_URL: http://127.0.0.1:3000 GITEA_ORG: giersig.eu OG_CACHE_DIR: /usr/local/git/.cache/og + UNFURL_CACHE_DIR: /usr/local/git/.cache/unfurl - name: Deploy via rsync run: | diff --git a/eleventy.config.js b/eleventy.config.js index 44f3e2d..628bb8c 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1854,7 +1854,9 @@ export default function (eleventyConfig) { // prefetchUrl() already caches responses on disk; re-calling it for known URLs // is pure overhead. Writing [...urls] (not [...seen, ...newUrls]) intentionally // prunes URLs from soft-deleted posts, preventing unbounded manifest growth. - const manifestPath = resolve(__dirname, ".cache", "unfurl-manifest.json"); + const manifestPath = process.env.UNFURL_CACHE_DIR + ? resolve(process.env.UNFURL_CACHE_DIR, "manifest.json") + : resolve(__dirname, ".cache", "unfurl-manifest.json"); let seen = new Set(); try { seen = new Set(JSON.parse(readFileSync(manifestPath, "utf-8"))); diff --git a/lib/unfurl-shortcode.js b/lib/unfurl-shortcode.js index 67dac41..7ceeb0b 100644 --- a/lib/unfurl-shortcode.js +++ b/lib/unfurl-shortcode.js @@ -3,7 +3,7 @@ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs"; import { resolve } from "path"; import { createHash } from "crypto"; -const CACHE_DIR = resolve(import.meta.dirname, "..", ".cache", "unfurl"); +const CACHE_DIR = process.env.UNFURL_CACHE_DIR || resolve(import.meta.dirname, "..", ".cache", "unfurl"); const CACHE_DURATION_MS = 7 * 24 * 60 * 60 * 1000; // 1 week const FAILURE_CACHE_MS = 7 * 24 * 60 * 60 * 1000; // 1 week — YouTube/bot-blocked sites never succeed, no point retrying daily const USER_AGENT = "Mozilla/5.0 (compatible; Indiekit/1.0; +https://getindiekit.com)";