perf: review-fixes (N+1, waterfalls, sanitize-cache, lazy strommix)
Deploy / verify (push) Successful in 56s
Deploy / deploy (push) Successful in 1m3s

- blog-utils.resolvePostOverviewBlocks: parallel getPostBySlug via
  Promise.all + .catch(null) instead of sequential await loop.
- blog-utils.resolveCalendarBlocks: same fix for calendar items.
- [...slug] page load: SearchableText/Calendar/DeadlineBanner now run
  parallel after tagsMap (was strict waterfall).
- sanitize-blocks: LRU cache keyed on raw html input — sanitize-html is
  ~ms/KB, the same content repeats across pages and cache hits.
- cms.getNormalizedTranslations: WeakMap-memoised the per-request
  Object.entries normalize loop on top of the existing 5-min bundle TTL.
- cms.cached: opt-in dev cache via DEV_CACHE_CMS=1 (default still off).
- rusty-image.ensureTransformedImage: was async-wrapping a sync URL
  builder; made sync, removed awaits at call sites — saves microtasks.
- BlockRenderer: lazy-load StrommixBlock (~220 KB) via dynamic import
  in the template — pages without the live-strommix widget no longer
  ship its bundle.

Also: enabled Caddy zstd+gzip on windwiderstand.de vhost (server-side
edit; verified `content-encoding: zstd` on response).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Peter Meier
2026-05-21 12:30:15 +02:00
parent c00eb26689
commit 81c82c33e6
9 changed files with 144 additions and 91 deletions
+23 -1
View File
@@ -62,8 +62,30 @@ const HTML_BLOCK_OPTIONS: sanitizeHtml.IOptions = {
},
};
/**
* Pro-Block-Hash-Cache: sanitize-html ist teuer (~ms pro KB), das CMS
* liefert dasselbe Markup wieder und wieder. Key = raw input, Value =
* sanitised output. Größe geclippt (LRU-ähnlich via Map-Insertion-Order).
*/
const SANITIZE_CACHE = new Map<string, string>();
const SANITIZE_CACHE_MAX = 500;
export function sanitizeUntrustedHtml(html: string): string {
return sanitizeHtml(html, HTML_BLOCK_OPTIONS);
const cached = SANITIZE_CACHE.get(html);
if (cached !== undefined) {
// Move to end (most-recently-used).
SANITIZE_CACHE.delete(html);
SANITIZE_CACHE.set(html, cached);
return cached;
}
const out = sanitizeHtml(html, HTML_BLOCK_OPTIONS);
SANITIZE_CACHE.set(html, out);
if (SANITIZE_CACHE.size > SANITIZE_CACHE_MAX) {
// Evict oldest.
const oldest = SANITIZE_CACHE.keys().next().value;
if (oldest !== undefined) SANITIZE_CACHE.delete(oldest);
}
return out;
}
type Block = { _type?: string; html?: unknown } & Record<string, unknown>;