Declare only the tables and columns pixa writes and reads (closes #310)
check / check (push) Canceled after 0s

Removes output_content and request_cache, which nothing writes, and every
column that was written but never read: the host, path, query, content_type
and fetched_at of source_content, the content_type and created_at of
variant_content, and the status_code, error_message and fetched_at of
negative_cache.

StoreSource no longer takes the fetch result and LookupSource returns only
the source key. StoreVariant no longer takes a content type and
StoreNegative no longer takes a status code or message, so
extractStatusCode and the status constants, which only fed status_code,
are gone. Reconciliation adopts a variant file without opening it, as its
row no longer records a content type. Tests that set or checked a removed
column follow.

Model: opus-5-5
This commit is contained in:
2026-10-21 16:32:49 +00:00
parent 5f9d624d74
commit 03b11e9703
19 changed files with 105 additions and 279 deletions
+9 -28
View File
@@ -16,7 +16,6 @@ import (
"modernc.org/sqlite"
"sneak.berlin/go/pixa/internal/database"
"sneak.berlin/go/pixa/internal/httpfetcher"
"sneak.berlin/go/pixa/internal/imagerequest"
)
@@ -102,17 +101,8 @@ func storeEvictionTestSource(
},
}
result := &httpfetcher.FetchResult{
StatusCode: 200,
ContentType: testContentTypeJPEG,
ContentLength: int64(len(content)),
Headers: map[string][]string{
testHeaderContentType: {testContentTypeJPEG},
},
}
key, err := cache.StoreSource(
context.Background(), req, bytes.NewReader(content), result,
context.Background(), req, bytes.NewReader(content),
)
if err != nil {
t.Fatalf("StoreSource(%s%s) failed: %v", host, path, err)
@@ -128,7 +118,7 @@ func storeEvictionTestVariant(
) {
t.Helper()
err := cache.StoreVariant(t.Context(), key, bytes.NewReader(content), "image/webp")
err := cache.StoreVariant(t.Context(), key, bytes.NewReader(content))
if err != nil {
t.Fatalf("StoreVariant(%s) failed: %v", key, err)
}
@@ -437,20 +427,13 @@ func assertDisabledCacheWritesAreNoOps(
ctx := t.Context()
err := cache.StoreVariant(
ctx, imagerequest.CacheKey(req), bytes.NewReader([]byte("data")), "image/webp",
ctx, imagerequest.CacheKey(req), bytes.NewReader([]byte("data")),
)
if err != nil {
t.Fatalf("StoreVariant on disabled cache must be a no-op, got error: %v", err)
}
result := &httpfetcher.FetchResult{
StatusCode: 200,
ContentType: testContentTypeJPEG,
ContentLength: 4,
Headers: map[string][]string{},
}
key, err := cache.StoreSource(ctx, req, bytes.NewReader([]byte("data")), result)
key, err := cache.StoreSource(ctx, req, bytes.NewReader([]byte("data")))
if err != nil {
t.Fatalf("StoreSource on disabled cache must be a no-op, got error: %v", err)
}
@@ -469,14 +452,13 @@ func assertDisabledCacheReadsAlwaysMiss(
ctx := t.Context()
key, srcType, err := cache.LookupSource(ctx, req)
key, err := cache.LookupSource(ctx, req)
if err != nil {
t.Fatalf("LookupSource on disabled cache failed: %v", err)
}
if key != "" || srcType != "" {
t.Errorf("LookupSource on disabled cache = (%q, %q), want empty",
key, srcType)
if key != "" {
t.Errorf("LookupSource on disabled cache = %q, want empty", key)
}
}
@@ -667,9 +649,8 @@ func TestStartEvictionReconcilesAccountingWithDisk(t *testing.T) {
// An accounting row whose file is missing must be dropped.
_, err = cache.db.ExecContext(t.Context(),
`INSERT INTO variant_content (cache_key, size_bytes, content_type)
VALUES (?, ?, ?)`,
"deadbeef0001", 700, "image/webp",
`INSERT INTO variant_content (cache_key, size_bytes) VALUES (?, ?)`,
"deadbeef0001", 700,
)
if err != nil {
t.Fatalf("failed to insert stale variant accounting row: %v", err)