mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-05 01:43:11 +03:00
Storm ChecksumsRepository complete.
This commit is contained in:
parent
4f151a7409
commit
c9be5f7201
@ -1,8 +1,6 @@
|
|||||||
package db_ledis
|
package db_ledis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/cloudsonic/sonic-server/log"
|
"github.com/cloudsonic/sonic-server/log"
|
||||||
"github.com/cloudsonic/sonic-server/scanner"
|
"github.com/cloudsonic/sonic-server/scanner"
|
||||||
"github.com/siddontang/ledisdb/ledis"
|
"github.com/siddontang/ledisdb/ledis"
|
||||||
@ -35,14 +33,6 @@ func (r *checkSumRepository) loadData() {
|
|||||||
log.Debug("Loaded checksums", "total", len(r.data))
|
log.Debug("Loaded checksums", "total", len(r.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *checkSumRepository) Put(id, sum string) error {
|
|
||||||
if id == "" {
|
|
||||||
return errors.New("ID is required")
|
|
||||||
}
|
|
||||||
_, err := Db().HSet(checkSumKeyName, []byte(id), []byte(sum))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *checkSumRepository) Get(id string) (string, error) {
|
func (r *checkSumRepository) Get(id string) (string, error) {
|
||||||
return r.data[id], nil
|
return r.data[id], nil
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Set = wire.NewSet(
|
var Set = wire.NewSet(
|
||||||
NewCheckSumRepository,
|
|
||||||
NewNowPlayingRepository,
|
NewNowPlayingRepository,
|
||||||
)
|
)
|
||||||
|
53
persistence/db_storm/checksum_repository.go
Normal file
53
persistence/db_storm/checksum_repository.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package db_storm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/asdine/storm"
|
||||||
|
"github.com/cloudsonic/sonic-server/domain"
|
||||||
|
"github.com/cloudsonic/sonic-server/log"
|
||||||
|
"github.com/cloudsonic/sonic-server/scanner"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
checkSumBucket = "_Checksums"
|
||||||
|
)
|
||||||
|
|
||||||
|
type checkSumRepository struct {
|
||||||
|
data map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCheckSumRepository() scanner.CheckSumRepository {
|
||||||
|
r := &checkSumRepository{}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *checkSumRepository) loadData() error {
|
||||||
|
loadedData := make(map[string]string)
|
||||||
|
err := Db().Get(checkSumBucket, checkSumBucket, &loadedData)
|
||||||
|
if err == storm.ErrNotFound {
|
||||||
|
return domain.ErrNotFound
|
||||||
|
}
|
||||||
|
log.Debug("Loaded checksums", "total", len(loadedData))
|
||||||
|
r.data = loadedData
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *checkSumRepository) Get(id string) (string, error) {
|
||||||
|
if r.data == nil {
|
||||||
|
err := r.loadData()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r.data[id], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *checkSumRepository) SetData(newSums map[string]string) error {
|
||||||
|
err := Db().Set(checkSumBucket, checkSumBucket, newSums)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.data = newSums
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ scanner.CheckSumRepository = (*checkSumRepository)(nil)
|
28
persistence/db_storm/checksum_repository_test.go
Normal file
28
persistence/db_storm/checksum_repository_test.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package db_storm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cloudsonic/sonic-server/scanner"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("ChecksumRepository", func() {
|
||||||
|
var repo scanner.CheckSumRepository
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
Db().Drop(checkSumBucket)
|
||||||
|
repo = NewCheckSumRepository()
|
||||||
|
repo.SetData(map[string]string{
|
||||||
|
"a": "AAA", "b": "BBB",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
It("can retrieve data", func() {
|
||||||
|
Expect(repo.Get("b")).To(Equal("BBB"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("persists data", func() {
|
||||||
|
newRepo := NewCheckSumRepository()
|
||||||
|
Expect(newRepo.Get("b")).To(Equal("BBB"))
|
||||||
|
})
|
||||||
|
})
|
@ -12,5 +12,6 @@ var Set = wire.NewSet(
|
|||||||
NewMediaFileRepository,
|
NewMediaFileRepository,
|
||||||
NewArtistIndexRepository,
|
NewArtistIndexRepository,
|
||||||
NewPlaylistRepository,
|
NewPlaylistRepository,
|
||||||
|
NewCheckSumRepository,
|
||||||
persistence.NewMediaFolderRepository,
|
persistence.NewMediaFolderRepository,
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,6 @@ func NewItunesScanner(checksumRepo CheckSumRepository) *ItunesScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CheckSumRepository interface {
|
type CheckSumRepository interface {
|
||||||
Put(id, sum string) error
|
|
||||||
Get(id string) (string, error)
|
Get(id string) (string, error)
|
||||||
SetData(newSums map[string]string) error
|
SetData(newSums map[string]string) error
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
// Injectors from wire_injectors.go:
|
// Injectors from wire_injectors.go:
|
||||||
|
|
||||||
func initImporter(musicFolder string) *scanner.Importer {
|
func initImporter(musicFolder string) *scanner.Importer {
|
||||||
checkSumRepository := db_ledis.NewCheckSumRepository()
|
checkSumRepository := db_storm.NewCheckSumRepository()
|
||||||
itunesScanner := scanner.NewItunesScanner(checkSumRepository)
|
itunesScanner := scanner.NewItunesScanner(checkSumRepository)
|
||||||
mediaFileRepository := db_storm.NewMediaFileRepository()
|
mediaFileRepository := db_storm.NewMediaFileRepository()
|
||||||
albumRepository := db_storm.NewAlbumRepository()
|
albumRepository := db_storm.NewAlbumRepository()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user