Return 404 when artwork is not available in /share/img endpoint

This commit is contained in:
Deluan
2023-01-31 18:22:49 -05:00
committed by Deluan Quintão
parent 128b626ec9
commit d8e794317f
13 changed files with 75 additions and 90 deletions
+6 -6
View File
@@ -30,7 +30,7 @@ func NewCacheWarmer(artwork Artwork, cache cache.FileCache) CacheWarmer {
a := &cacheWarmer{
artwork: artwork,
cache: cache,
buffer: make(map[string]struct{}),
buffer: make(map[model.ArtworkID]struct{}),
wakeSignal: make(chan struct{}, 1),
}
@@ -42,7 +42,7 @@ func NewCacheWarmer(artwork Artwork, cache cache.FileCache) CacheWarmer {
type cacheWarmer struct {
artwork Artwork
buffer map[string]struct{}
buffer map[model.ArtworkID]struct{}
mutex sync.Mutex
cache cache.FileCache
wakeSignal chan struct{}
@@ -51,7 +51,7 @@ type cacheWarmer struct {
func (a *cacheWarmer) PreCache(artID model.ArtworkID) {
a.mutex.Lock()
defer a.mutex.Unlock()
a.buffer[artID.String()] = struct{}{}
a.buffer[artID] = struct{}{}
a.sendWakeSignal()
}
@@ -87,7 +87,7 @@ func (a *cacheWarmer) run(ctx context.Context) {
}
batch := maps.Keys(a.buffer)
a.buffer = make(map[string]struct{})
a.buffer = make(map[model.ArtworkID]struct{})
a.mutex.Unlock()
a.processBatch(ctx, batch)
@@ -108,7 +108,7 @@ func (a *cacheWarmer) waitSignal(ctx context.Context, timeout time.Duration) {
}
}
func (a *cacheWarmer) processBatch(ctx context.Context, batch []string) {
func (a *cacheWarmer) processBatch(ctx context.Context, batch []model.ArtworkID) {
log.Trace(ctx, "PreCaching a new batch of artwork", "batchSize", len(batch))
input := pl.FromSlice(ctx, batch)
errs := pl.Sink(ctx, 2, input, a.doCacheImage)
@@ -117,7 +117,7 @@ func (a *cacheWarmer) processBatch(ctx context.Context, batch []string) {
}
}
func (a *cacheWarmer) doCacheImage(ctx context.Context, id string) error {
func (a *cacheWarmer) doCacheImage(ctx context.Context, id model.ArtworkID) error {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()