One file store type for cached sources and variants #318

Closed
opened 2026-10-21 12:51:08 +02:00 by clawbot · 2 comments
Collaborator

Item 12 of 15 of #168: "Collapse the three storage structs into one". Starts when #317 is squash-merged to next.

Today (next at 989da78)

ContentStorage, VariantStorage and MetadataStorage in internal/imgcache/storage.go each implement the same write-to-temp-file-then-rename, the same two-level directory fan-out and the same load, exists and delete, differing only in who chooses the key and in the .meta file. After #308 and #309 the .meta file and the metadata directory are gone and sources and variants are both named by a key.

Name, recorded here

The one type is FileStore (the proposal in #168): a directory of files named by a hex key.

Definition of done

  • One type, imgcache.FileStore, writes a file under a temp name, syncs it and renames it into place, opens, reports the size of, and deletes the file for a key, with the two-level fan-out; the cache uses one for sources and one for variants.
  • ContentStorage, VariantStorage and whatever is left of MetadataStorage are gone; there is one copy of the atomic write.
  • The startup and periodic checks of cached files keep working on both stores.
  • Tests of the three old types that test behaviour the one type keeps move to it.

Approval and tests

sneak asked for each main recommendation of #168 to be its own issue, built before 1.0, one at a time in the order listed (#168 (comment)). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped.

Model: opus-5-5

Item 12 of 15 of https://git.eeqj.de/sneak/pixa/issues/168: "Collapse the three storage structs into one". Starts when https://git.eeqj.de/sneak/pixa/issues/317 is squash-merged to `next`. ## Today (`next` at `989da78`) `ContentStorage`, `VariantStorage` and `MetadataStorage` in `internal/imgcache/storage.go` each implement the same write-to-temp-file-then-rename, the same two-level directory fan-out and the same load, exists and delete, differing only in who chooses the key and in the `.meta` file. After https://git.eeqj.de/sneak/pixa/issues/308 and https://git.eeqj.de/sneak/pixa/issues/309 the `.meta` file and the metadata directory are gone and sources and variants are both named by a key. ## Name, recorded here The one type is `FileStore` (the proposal in https://git.eeqj.de/sneak/pixa/issues/168): a directory of files named by a hex key. ## Definition of done - One type, `imgcache.FileStore`, writes a file under a temp name, syncs it and renames it into place, opens, reports the size of, and deletes the file for a key, with the two-level fan-out; the cache uses one for sources and one for variants. - `ContentStorage`, `VariantStorage` and whatever is left of `MetadataStorage` are gone; there is one copy of the atomic write. - The startup and periodic checks of cached files keep working on both stores. - Tests of the three old types that test behaviour the one type keeps move to it. ## Approval and tests sneak asked for each main recommendation of https://git.eeqj.de/sneak/pixa/issues/168 to be its own issue, built before 1.0, one at a time in the order listed (https://git.eeqj.de/sneak/pixa/issues/168#issuecomment-153513). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped. Model: opus-5-5
clawbot added this to the 1.0.0 milestone 2026-10-21 12:51:08 +02:00
clawbot self-assigned this 2026-10-21 12:51:08 +02:00
Author
Collaborator

Scope, decided from the record: two leftovers in internal/imgcache that reviews of #334 found go in this item, since it rewrites that code.

  • ContentStorage.Exists has no caller outside tests; FileStore gets no Exists, and its tests check the file on disk.
  • internal/imgcache/testdata/red.avif is used by no test; it is deleted if that still holds.

Model: opus-5-5

Scope, decided from the record: two leftovers in `internal/imgcache` that reviews of https://git.eeqj.de/sneak/pixa/pulls/334 found go in this item, since it rewrites that code. - `ContentStorage.Exists` has no caller outside tests; `FileStore` gets no `Exists`, and its tests check the file on disk. - `internal/imgcache/testdata/red.avif` is used by no test; it is deleted if that still holds. Model: opus-5-5
Author
Collaborator

Built in #335. imgcache.FileStore has Write, Open, Size and Delete. The cache keeps its sources in one and its variants in another, and ContentStorage and VariantStorage are gone.

  • FileStore has no Exists. The reconciliation pass called VariantStorage.Exists in production, so it now checks a variant's file with Size.
  • Cache.Variant reads the content type from the file's first bytes.
  • internal/imgcache/testdata/red.avif is deleted.

Model: opus-5-5

Built in https://git.eeqj.de/sneak/pixa/pulls/335. `imgcache.FileStore` has `Write`, `Open`, `Size` and `Delete`. The cache keeps its sources in one and its variants in another, and `ContentStorage` and `VariantStorage` are gone. - `FileStore` has no `Exists`. The reconciliation pass called `VariantStorage.Exists` in production, so it now checks a variant's file with `Size`. - `Cache.Variant` reads the content type from the file's first bytes. - `internal/imgcache/testdata/red.avif` is deleted. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#318