Cache.Stats reads never-populated output_content/request_cache tables, so TotalItems and TotalSizeBytes are always 0 #56

Open
opened 2026-08-07 23:13:03 +02:00 by clawbot · 0 comments
Collaborator

Discovered while implementing #51 (out of scope there, filing per repo policy).

Cache.Stats in internal/imgcache/cache.go computes TotalItems from request_cache and TotalSizeBytes from output_content:

_ = c.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM request_cache`).Scan(&stats.TotalItems)
_ = c.db.QueryRowContext(ctx, `SELECT COALESCE(SUM(size_bytes), 0) FROM output_content`).Scan(&stats.TotalSizeBytes)

No code path ever inserts into output_content or request_cache (they were created by migration 001 for a design that stored variants content-addressed with a request mapping, but the implementation went with key-addressed VariantStorage instead). Both stats are therefore always 0.

Since #51 (PR #55), real accounting exists: variant_content tracks processed variants and source_content tracks source blobs, and Cache.UsageBytes returns the true total. Suggested fix:

  1. Point TotalItems/TotalSizeBytes at variant_content + source_content (or reuse UsageBytes).
  2. Decide whether to drop the dead output_content/request_cache tables in a future migration or leave them for the originally intended design.

Also worth a look in the same pass: the metaCache field on Cache (in-memory variant meta cache) is initialized but never read or written.

Discovered while implementing #51 (out of scope there, filing per repo policy). `Cache.Stats` in `internal/imgcache/cache.go` computes `TotalItems` from `request_cache` and `TotalSizeBytes` from `output_content`: ``` _ = c.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM request_cache`).Scan(&stats.TotalItems) _ = c.db.QueryRowContext(ctx, `SELECT COALESCE(SUM(size_bytes), 0) FROM output_content`).Scan(&stats.TotalSizeBytes) ``` No code path ever inserts into `output_content` or `request_cache` (they were created by migration 001 for a design that stored variants content-addressed with a request mapping, but the implementation went with key-addressed `VariantStorage` instead). Both stats are therefore always 0. Since #51 (PR #55), real accounting exists: `variant_content` tracks processed variants and `source_content` tracks source blobs, and `Cache.UsageBytes` returns the true total. Suggested fix: 1. Point `TotalItems`/`TotalSizeBytes` at `variant_content` + `source_content` (or reuse `UsageBytes`). 2. Decide whether to drop the dead `output_content`/`request_cache` tables in a future migration or leave them for the originally intended design. Also worth a look in the same pass: the `metaCache` field on `Cache` (in-memory variant meta cache) is initialized but never read or written.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#56