Don't wake CacheWarmer every 10 seconds, let it sleep :)
This commit is contained in:
parent
136d5f9a83
commit
7fc964aec5
|
@ -65,11 +65,10 @@ func (a *cacheWarmer) sendWakeSignal() {
|
||||||
|
|
||||||
func (a *cacheWarmer) run(ctx context.Context) {
|
func (a *cacheWarmer) run(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
t := time.AfterFunc(10*time.Second, func() {
|
a.waitSignal(ctx, 10*time.Second)
|
||||||
a.sendWakeSignal()
|
if ctx.Err() != nil {
|
||||||
})
|
break
|
||||||
<-a.wakeSignal
|
}
|
||||||
t.Stop()
|
|
||||||
|
|
||||||
// If cache not available, keep waiting
|
// If cache not available, keep waiting
|
||||||
if !a.cache.Available(ctx) {
|
if !a.cache.Available(ctx) {
|
||||||
|
@ -95,6 +94,20 @@ func (a *cacheWarmer) run(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *cacheWarmer) waitSignal(ctx context.Context, timeout time.Duration) {
|
||||||
|
var to <-chan time.Time
|
||||||
|
if !a.cache.Available(ctx) {
|
||||||
|
tmr := time.NewTimer(timeout)
|
||||||
|
defer tmr.Stop()
|
||||||
|
to = tmr.C
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-to:
|
||||||
|
case <-a.wakeSignal:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *cacheWarmer) processBatch(ctx context.Context, batch []string) {
|
func (a *cacheWarmer) processBatch(ctx context.Context, batch []string) {
|
||||||
log.Trace(ctx, "PreCaching a new batch of artwork", "batchSize", len(batch))
|
log.Trace(ctx, "PreCaching a new batch of artwork", "batchSize", len(batch))
|
||||||
input := pl.FromSlice(ctx, batch)
|
input := pl.FromSlice(ctx, batch)
|
||||||
|
|
|
@ -7,12 +7,13 @@ import (
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
|
"github.com/navidrome/navidrome/utils/pl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newBufferedScrobbler(ds model.DataStore, s Scrobbler, service string) *bufferedScrobbler {
|
func newBufferedScrobbler(ds model.DataStore, s Scrobbler, service string) *bufferedScrobbler {
|
||||||
b := &bufferedScrobbler{ds: ds, wrapped: s, service: service}
|
b := &bufferedScrobbler{ds: ds, wrapped: s, service: service}
|
||||||
b.wakeSignal = make(chan struct{}, 1)
|
b.wakeSignal = make(chan struct{}, 1)
|
||||||
go b.run()
|
go b.run(context.TODO())
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,15 +50,14 @@ func (b *bufferedScrobbler) sendWakeSignal() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bufferedScrobbler) run() {
|
func (b *bufferedScrobbler) run(ctx context.Context) {
|
||||||
ctx := context.Background()
|
|
||||||
for {
|
for {
|
||||||
if !b.processQueue(ctx) {
|
if !b.processQueue(ctx) {
|
||||||
time.AfterFunc(5*time.Second, func() {
|
time.AfterFunc(5*time.Second, func() {
|
||||||
b.sendWakeSignal()
|
b.sendWakeSignal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
<-b.wakeSignal
|
<-pl.ReadOrDone(ctx, b.wakeSignal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue