mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
refactor(model): name the artwork mime lookup for what it is keyed by
GetAllMimes reads as a collection of mime types; it returns a hash -> mime index over every stored artwork. GetMimeByHash names the key, matching the convention the other map-returning repository methods already follow (CountBySuffix, CountByClient).
This commit is contained in:
parent
3be5fbd222
commit
cdb9f44735
@ -44,7 +44,7 @@ func prune(ctx context.Context, ds model.DataStore, store *ImageStore) error {
|
||||
}
|
||||
|
||||
// Read after the delete, so the sweep below reclaims the files of the rows just removed.
|
||||
mimes, err := repo.GetAllMimes()
|
||||
mimes, err := repo.GetMimeByHash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ type flakyGetArtworkRepo struct {
|
||||
*tests.MockArtworkRepo
|
||||
}
|
||||
|
||||
func (f *flakyGetArtworkRepo) GetAllMimes() (map[string]string, error) {
|
||||
func (f *flakyGetArtworkRepo) GetMimeByHash() (map[string]string, error) {
|
||||
return nil, errors.New("db locked")
|
||||
}
|
||||
|
||||
|
||||
@ -106,8 +106,8 @@ type ArtworkRepository interface {
|
||||
DeleteForItems(kind Kind, ids []string) error
|
||||
// GetInfoForItems hydrates a page in one batched query.
|
||||
GetInfoForItems(kind Kind, ids []string) (map[string]ItemArtworkInfo, error)
|
||||
// GetAllMimes returns hash -> current mime for every stored artwork.
|
||||
GetAllMimes() (map[string]string, error)
|
||||
// GetMimeByHash returns hash -> current mime for every stored artwork.
|
||||
GetMimeByHash() (map[string]string, error)
|
||||
// PurgeDanglingItemArtwork removes state rows whose entity no longer exists.
|
||||
PurgeDanglingItemArtwork() (int64, error)
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ func (r *artworkRepository) PutImage(a *model.Artwork) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *artworkRepository) GetAllMimes() (map[string]string, error) {
|
||||
func (r *artworkRepository) GetMimeByHash() (map[string]string, error) {
|
||||
sel := Select("hash", "mime").From(r.tableName)
|
||||
var rows []struct {
|
||||
Hash string
|
||||
|
||||
@ -89,7 +89,7 @@ var _ = Describe("ArtworkRepository", func() {
|
||||
It("returns every stored hash with its current mime", func() {
|
||||
Expect(repo.PutImage(&model.Artwork{Hash: "all1", Mime: "image/jpeg"})).To(Succeed())
|
||||
Expect(repo.PutImage(&model.Artwork{Hash: "all2", Mime: "image/png"})).To(Succeed())
|
||||
mimes, err := repo.GetAllMimes()
|
||||
mimes, err := repo.GetMimeByHash()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mimes).To(HaveKeyWithValue("all1", "image/jpeg"))
|
||||
Expect(mimes).To(HaveKeyWithValue("all2", "image/png"))
|
||||
|
||||
@ -50,7 +50,7 @@ func (m *MockArtworkRepo) PutImage(a *model.Artwork) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockArtworkRepo) GetAllMimes() (map[string]string, error) {
|
||||
func (m *MockArtworkRepo) GetMimeByHash() (map[string]string, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.Err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user