mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
scanner: remove cached genre repository
Not needed anytmore. And remember: "Many Small Queries Are Efficient In SQLite" [1]. [1]: https://www.sqlite.org/np1queryprob.html
This commit is contained in:
parent
0a225107e4
commit
c5d900aa43
3 changed files with 1 additions and 47 deletions
|
@ -1,45 +0,0 @@
|
|||
package scanner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ReneKroon/ttlcache/v2"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
)
|
||||
|
||||
func newCachedGenreRepository(ctx context.Context, repo model.GenreRepository) model.GenreRepository {
|
||||
r := &cachedGenreRepo{
|
||||
GenreRepository: repo,
|
||||
ctx: ctx,
|
||||
}
|
||||
genres, err := repo.GetAll()
|
||||
if err != nil {
|
||||
log.Error(ctx, "Could not load genres from DB", err)
|
||||
return repo
|
||||
}
|
||||
|
||||
r.cache = ttlcache.NewCache()
|
||||
for _, g := range genres {
|
||||
_ = r.cache.Set(strings.ToLower(g.Name), g.ID)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
type cachedGenreRepo struct {
|
||||
model.GenreRepository
|
||||
cache *ttlcache.Cache
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (r *cachedGenreRepo) Put(g *model.Genre) error {
|
||||
id, err := r.cache.GetByLoader(strings.ToLower(g.Name), func(key string) (interface{}, time.Duration, error) {
|
||||
err := r.GenreRepository.Put(g)
|
||||
return g.ID, 24 * time.Hour, err
|
||||
})
|
||||
g.ID = id.(string)
|
||||
return err
|
||||
}
|
|
@ -34,7 +34,6 @@ var _ = Describe("mapping", func() {
|
|||
ctx = context.Background()
|
||||
ds := &tests.MockDataStore{}
|
||||
gr = ds.Genre(ctx)
|
||||
gr = newCachedGenreRepository(ctx, gr)
|
||||
mapper = newMediaFileMapper("/", gr)
|
||||
})
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time, prog
|
|||
allFSDirs := dirMap{}
|
||||
var changedDirs []string
|
||||
s.cnt = &counters{}
|
||||
genres := newCachedGenreRepository(ctx, s.ds.Genre(ctx))
|
||||
genres := s.ds.Genre(ctx)
|
||||
s.mapper = newMediaFileMapper(s.rootFolder, genres)
|
||||
|
||||
foldersFound, walkerError := s.getRootFolderWalker(ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue