Have Lookup check the disk for variants held in memory too (closes #70)
check / check (push) Successful in 3m36s
check / check (push) Successful in 3m36s
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
This commit is contained in:
@@ -34,12 +34,12 @@ exhaustion
|
|||||||
`Cache.metaCache` holds the content types of up to 10,000 variants in an LRU
|
`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
|
(`github.com/hashicorp/golang-lru/v2`), filled by `StoreVariant` and by
|
||||||
`GetVariant` after it reads a `.meta` file, where a type `StoreVariant` added
|
`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`
|
meanwhile is kept over the one read; for a variant it holds, `GetVariant`
|
||||||
skips the check of the disk and `GetVariant` skips the `.meta` read, still
|
skips the `.meta` read, still opening the variant file and taking the size
|
||||||
opening the variant file and taking the size from it; eviction removes the
|
from it; eviction removes the entry before deleting the files, and
|
||||||
entry before deleting the files, and `GetVariant` removes it when the file
|
`GetVariant` removes it when the file will not open; the cap is a constant,
|
||||||
will not open; the cap is a constant, not a setting; the unused `variantMeta`
|
not a setting; the unused `variantMeta` type is gone; `README.md` describes
|
||||||
type is gone; `README.md` describes it.
|
it.
|
||||||
- 2026-09-29 Dockerfiles install through `script/bootstrap` (closes #95): the
|
- 2026-09-29 Dockerfiles install through `script/bootstrap` (closes #95): the
|
||||||
`Dockerfile` lint and build stages and `Dockerfile.lint` copy `script/`,
|
`Dockerfile` lint and build stages and `Dockerfile.lint` copy `script/`,
|
||||||
`go.mod` and `go.sum`, then run `script/bootstrap` in place of their own
|
`go.mod` and `go.sum`, then run `script/bootstrap` in place of their own
|
||||||
|
|||||||
@@ -159,15 +159,13 @@ type LookupResult struct {
|
|||||||
CacheStatus CacheStatus
|
CacheStatus CacheStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup checks if a processed variant exists on disk: a variant held
|
// Lookup checks if a processed variant exists on disk. Hits touch the
|
||||||
// in metaCache counts as present without a check of the disk. Hits
|
// variant's LRU timestamp; a disabled cache always misses.
|
||||||
// touch the variant's LRU timestamp; a disabled cache always misses.
|
|
||||||
func (c *Cache) Lookup(ctx context.Context, req *ImageRequest) (*LookupResult, error) {
|
func (c *Cache) Lookup(ctx context.Context, req *ImageRequest) (*LookupResult, error) {
|
||||||
cacheKey := CacheKey(req)
|
cacheKey := CacheKey(req)
|
||||||
|
|
||||||
// Check memory, then variant storage - no DB needed for cache hits
|
// Check variant storage directly - no DB needed for cache hits
|
||||||
if !c.disabled &&
|
if !c.disabled && c.variants.Exists(cacheKey) {
|
||||||
(c.metaCache.Contains(cacheKey) || c.variants.Exists(cacheKey)) {
|
|
||||||
c.touchVariant(ctx, cacheKey)
|
c.touchVariant(ctx, cacheKey)
|
||||||
|
|
||||||
return &LookupResult{
|
return &LookupResult{
|
||||||
|
|||||||
Reference in New Issue
Block a user