mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 02:17:25 +02:00
fix(server): update StoreMusicFolder to skip updates when path is unchanged
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
c534aedd0c
commit
072331078d
2 changed files with 46 additions and 3 deletions
|
|
@ -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.MusicFolder
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue