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 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.

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:22:28 +00:00
parent 5f9d624d74
commit a6eba6045e
17 changed files with 78 additions and 226 deletions
+5 -19
View File
@@ -51,11 +51,6 @@ const sqliteTimestampLayout = "2006-01-02 15:04:05"
// writes (".tmp-*" patterns in the storage layer).
const tempFilePrefix = ".tmp-"
// fallbackContentType is the content type reconciliation records for a
// variant file it adopts whose first bytes are not those of an output
// format. Such a file is never served.
const fallbackContentType = "application/octet-stream"
// UsageBytes returns the total number of bytes of cache content
// tracked in the database (source content blobs plus processed
// variants). It reads the total the database keeps up to date as rows
@@ -590,25 +585,16 @@ func (c *Cache) reconcileVariantFile(
}
// adoptVariantFile inserts an accounting row for a variant file that
// has none, using the file's size and modification time, and the content
// type its first bytes show, as a hit reads it.
// has none, using the file's size and modification time.
func (c *Cache) adoptVariantFile(
ctx context.Context, info fs.FileInfo, cacheKey imagerequest.VariantKey,
) error {
modTime := info.ModTime().UTC().Format(sqliteTimestampLayout)
contentType := fallbackContentType
content, _, detectedType, err := c.variants.LoadWithContentType(cacheKey)
if err == nil {
_ = content.Close()
contentType = detectedType
}
_, err = c.db.ExecContext(ctx, `
INSERT INTO variant_content
(cache_key, size_bytes, content_type, created_at, last_accessed_at)
VALUES (?, ?, ?, ?, ?)
`, string(cacheKey), info.Size(), contentType, modTime, modTime)
_, err := c.db.ExecContext(ctx, `
INSERT INTO variant_content (cache_key, size_bytes, last_accessed_at)
VALUES (?, ?, ?)
`, string(cacheKey), info.Size(), modTime)
if err != nil {
return fmt.Errorf("failed to adopt variant file into accounting: %w", err)
}