From c7e4eacd87c701242ae35741bcd20d2c253d059c Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Tue, 29 Sep 2026 07:30:24 +0000 Subject: [PATCH] Have Lookup check the disk for variants held in memory too (closes #70) Lookup again counts a variant as present only when its file exists. Treating a variant held in memory as present saved one check of the disk, but no test covered it, and GetVariant opens the file anyway. Model: opus-5-5 --- TODO.md | 12 ++++++------ internal/imgcache/cache.go | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/TODO.md b/TODO.md index 5f22565..4cbc167 100644 --- a/TODO.md +++ b/TODO.md @@ -33,12 +33,12 @@ P2: security: referer blacklist `Cache.metaCache` holds the content types of up to 10,000 variants in an LRU (`github.com/hashicorp/golang-lru/v2`), filled by `StoreVariant` and by `GetVariant` after it reads a `.meta` file, where a type `StoreVariant` added - meanwhile is kept over the one read; for a variant it holds, `Lookup` - skips the check of the disk and `GetVariant` skips the `.meta` read, still - opening the variant file and taking the size from it; eviction removes the - entry before deleting the files, and `GetVariant` removes it when the file - will not open; the cap is a constant, not a setting; the unused `variantMeta` - type is gone; `README.md` describes it. + meanwhile is kept over the one read; for a variant it holds, `GetVariant` + skips the `.meta` read, still opening the variant file and taking the size + from it; eviction removes the entry before deleting the files, and + `GetVariant` removes it when the file will not open; the cap is a constant, + not a setting; the unused `variantMeta` type is gone; `README.md` describes + it. - 2026-09-29 maintenance mode refuses image requests (closes #71): while `maintenance_mode` is on, `/v1/image/` and `/v1/e/` answer 503 with a `Retry-After` header and the JSON error body, from one middleware in diff --git a/internal/imgcache/cache.go b/internal/imgcache/cache.go index 43933db..2a87900 100644 --- a/internal/imgcache/cache.go +++ b/internal/imgcache/cache.go @@ -159,15 +159,13 @@ type LookupResult struct { CacheStatus CacheStatus } -// Lookup checks if a processed variant exists on disk: a variant held -// in metaCache counts as present without a check of the disk. Hits -// touch the variant's LRU timestamp; a disabled cache always misses. +// Lookup checks if a processed variant exists on disk. Hits touch the +// variant's LRU timestamp; a disabled cache always misses. func (c *Cache) Lookup(ctx context.Context, req *ImageRequest) (*LookupResult, error) { cacheKey := CacheKey(req) - // Check memory, then variant storage - no DB needed for cache hits - if !c.disabled && - (c.metaCache.Contains(cacheKey) || c.variants.Exists(cacheKey)) { + // Check variant storage directly - no DB needed for cache hits + if !c.disabled && c.variants.Exists(cacheKey) { c.touchVariant(ctx, cacheKey) return &LookupResult{