Keep posters and casts between runs
Posters (the downloaded bytes, per size, 30 days, at most 200 MB) and casts (people.json, 7 days, at most 2000) are stored in the user's cache directory (os.UserCacheDir()/arr-tui) and used on the next start before asking the servers. Expired posters are pruned at startup, casts are written shortly after new ones arrive and on exit. Tests turn the cache off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
-3
@@ -525,9 +525,23 @@ func (a *App) loadCover(ref coverRef, done func(*image.RGBA, error)) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
|
||||
defer cancel()
|
||||
var img *image.RGBA
|
||||
data, err := ref.fetch(ctx, large)
|
||||
if err == nil {
|
||||
img, err = decodeCover(data, maxHeight)
|
||||
var err error
|
||||
// A copy from an earlier run is used while it is fresh enough.
|
||||
if data, ok := a.disk.readPoster(ref.key, large); ok {
|
||||
if img, err = decodeCover(data, maxHeight); err != nil {
|
||||
a.disk.dropPoster(ref.key, large)
|
||||
img = nil
|
||||
}
|
||||
}
|
||||
if img == nil {
|
||||
var data []byte
|
||||
data, err = ref.fetch(ctx, large)
|
||||
if err == nil {
|
||||
img, err = decodeCover(data, maxHeight)
|
||||
}
|
||||
if err == nil {
|
||||
a.disk.writePoster(ref.key, large, data)
|
||||
}
|
||||
}
|
||||
a.post(func() {
|
||||
waiters := c.waiting[ref.key]
|
||||
|
||||
Reference in New Issue
Block a user