From f49205733b81f1f22657e14d7478ea2b1cf70b8f Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 2 Jul 2021 09:54:09 -0400 Subject: [PATCH] Add feature flag for buffered scrobbling --- conf/configuration.go | 2 ++ core/scrobbler/play_tracker.go | 6 +++++- core/scrobbler/play_tracker_test.go | 12 +++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/conf/configuration.go b/conf/configuration.go index ab81de6db..70e27b47c 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -70,6 +70,7 @@ type configOptions struct { DevOldCacheLayout bool DevActivityPanel bool DevEnableShare bool + DevEnableBufferedScrobble bool } type scannerOptions struct { @@ -229,6 +230,7 @@ func init() { viper.SetDefault("devfastaccesscoverart", false) viper.SetDefault("devactivitypanel", true) viper.SetDefault("devenableshare", false) + viper.SetDefault("devenablebufferedscrobble", false) } func InitConfig(cfgFile string) { diff --git a/core/scrobbler/play_tracker.go b/core/scrobbler/play_tracker.go index 0b8ebf761..79f469716 100644 --- a/core/scrobbler/play_tracker.go +++ b/core/scrobbler/play_tracker.go @@ -5,6 +5,8 @@ import ( "sort" "time" + "github.com/navidrome/navidrome/conf" + "github.com/ReneKroon/ttlcache/v2" "github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/model" @@ -50,7 +52,9 @@ func GetPlayTracker(ds model.DataStore, broker events.Broker) PlayTracker { p.scrobblers = make(map[string]Scrobbler) for name, constructor := range constructors { s := constructor(ds) - s = NewBufferedScrobbler(ds, s, name) + if conf.Server.DevEnableBufferedScrobble { + s = NewBufferedScrobbler(ds, s, name) + } p.scrobblers[name] = s } return p diff --git a/core/scrobbler/play_tracker_test.go b/core/scrobbler/play_tracker_test.go index 8467805bb..0b42d2072 100644 --- a/core/scrobbler/play_tracker_test.go +++ b/core/scrobbler/play_tracker_test.go @@ -5,6 +5,8 @@ import ( "errors" "time" + "github.com/navidrome/navidrome/conf" + "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/model/request" "github.com/navidrome/navidrome/server/events" @@ -23,6 +25,9 @@ var _ = Describe("PlayTracker", func() { var fake fakeScrobbler BeforeEach(func() { + // Remove buffering to simplify tests + conf.Server.DevEnableBufferedScrobble = false + ctx = context.Background() ctx = request.WithUser(ctx, model.User{ID: "u-1"}) ctx = request.WithPlayer(ctx, model.Player{ScrobbleEnabled: true}) @@ -33,13 +38,6 @@ var _ = Describe("PlayTracker", func() { }) tracker = GetPlayTracker(ds, events.GetBroker()) - // Remove buffering to simplify tests - for i, s := range tracker.(*playTracker).scrobblers { - if bs, ok := s.(*bufferedScrobbler); ok { - tracker.(*playTracker).scrobblers[i] = bs.wrapped - } - } - track = model.MediaFile{ ID: "123", Title: "Track Title",