🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
fix(server): update StoreMusicFolder to skip updates when path is unchanged
Deluan072331078d7a
diff --git a/persistence/library_repository.go b/persistence/library_repository.goindex df5c9a066..2e8feea7a 100644--- a/persistence/library_repository.go+++ b/persistence/library_repository.go@@ -137,9 +137,10 @@ ON CONFLICT (user_id, library_id) DO NOTHING;`,func (r *libraryRepository) StoreMusicFolder() error {sq := Update(r.tableName).Set("path", conf.Server.MusicFolder).Set("updated_at", time.Now()).- Where(Eq{"id": model.DefaultLibraryID})- _, err := r.executeSQL(sq)- if err != nil {+ Where(Eq{"id": model.DefaultLibraryID}).+ Where(NotEq{"path": conf.Server.MusicFolder})+ rowsAffected, err := r.executeSQL(sq)+ if err == nil && rowsAffected > 0 {libLock.Lock()defer libLock.Unlock()libCache[model.DefaultLibraryID] = conf.Server.MusicFolderdiff --git a/persistence/library_repository_test.go b/persistence/library_repository_test.goindex 949dd93c5..6aede8c4e 100644--- a/persistence/library_repository_test.go+++ b/persistence/library_repository_test.go@@ -5,6 +5,8 @@ import ("time""github.com/Masterminds/squirrel"+ "github.com/navidrome/navidrome/conf"+ "github.com/navidrome/navidrome/conf/configtest""github.com/navidrome/navidrome/log""github.com/navidrome/navidrome/model""github.com/navidrome/navidrome/model/request"@@ -139,6 +141,46 @@ var _ = Describe("LibraryRepository", func() {})})+ Describe("StoreMusicFolder", func() {+ var libBefore *model.Library++ BeforeEach(func() {+ var err error+ libBefore, err = repo.Get(model.DefaultLibraryID)+ Expect(err).ToNot(HaveOccurred())++ DeferCleanup(configtest.SetupConfig())+ DeferCleanup(func() {+ _, _ = conn.NewQuery("update library set path = {:path}, updated_at = {:updated_at} where id = {:id}").+ Bind(dbx.Params{"path": libBefore.Path, "updated_at": libBefore.UpdatedAt, "id": model.DefaultLibraryID}).+ Execute()+ libLock.Lock()+ defer libLock.Unlock()+ delete(libCache, model.DefaultLibraryID)+ })+ })++ It("skips updating the default library when the configured path is unchanged", func() {+ conf.Server.MusicFolder = libBefore.Path+ Expect(repo.StoreMusicFolder()).To(Succeed())++ libAfter, err := repo.Get(model.DefaultLibraryID)+ Expect(err).ToNot(HaveOccurred())+ Expect(libAfter.Path).To(Equal(libBefore.Path))+ Expect(libAfter.UpdatedAt).To(Equal(libBefore.UpdatedAt))+ })++ It("updates the default library only when the configured path changes", func() {+ conf.Server.MusicFolder = libBefore.Path + "-updated"+ Expect(repo.StoreMusicFolder()).To(Succeed())++ libAfter, err := repo.Get(model.DefaultLibraryID)+ Expect(err).ToNot(HaveOccurred())+ Expect(libAfter.Path).To(Equal(conf.Server.MusicFolder))+ Expect(libAfter.UpdatedAt).ToNot(Equal(libBefore.UpdatedAt))+ })+ })+It("refreshes stats", func() {libBefore, err := repo.Get(1)Expect(err).ToNot(HaveOccurred())