mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
fix(persistence): recompute the cached average rating after merging annotations
Merging the discarded row's annotations grows the rating population of the surviving track, so media_file.average_rating no longer matched what the annotation rows say. Only reachable since the remap started merging those rows instead of deleting them.
This commit is contained in:
parent
f5996711f4
commit
1d592af243
@ -404,6 +404,10 @@ func (r *mediaFileRepository) ReassignReferences(prevID, newID string) error {
|
||||
if err := r.ReassignAnnotation(prevID, newID); err != nil {
|
||||
return fmt.Errorf("reassigning annotations: %w", err)
|
||||
}
|
||||
// The merged rows change the rating population, so the cached average no longer matches
|
||||
if err := r.updateAvgRating(newID); err != nil {
|
||||
return fmt.Errorf("recomputing average rating: %w", err)
|
||||
}
|
||||
if err := r.reassignBookmark(prevID, newID); err != nil {
|
||||
return fmt.Errorf("reassigning bookmarks: %w", err)
|
||||
}
|
||||
|
||||
@ -989,6 +989,18 @@ var _ = Describe("MediaRepository", func() {
|
||||
Expect(entry.MediaFile.ID).To(Equal(next.ID))
|
||||
})
|
||||
|
||||
It("recomputes the average rating after merging another user's annotation", func() {
|
||||
other := NewMediaFileRepository(request.WithUser(log.NewContext(context.TODO()), model.User{ID: "2222"}), GetDBXBuilder())
|
||||
Expect(mr.SetRating(5, next.ID)).To(Succeed())
|
||||
Expect(other.SetRating(3, prev.ID)).To(Succeed())
|
||||
|
||||
Expect(mr.ReassignReferences(prev.ID, next.ID)).To(Succeed())
|
||||
|
||||
got, err := mr.Get(next.ID)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(got.AverageRating).To(Equal(4.0))
|
||||
})
|
||||
|
||||
It("keeps the new id's own annotation and bookmark when both exist", func() {
|
||||
Expect(mr.SetRating(5, prev.ID)).To(Succeed())
|
||||
Expect(mr.SetRating(1, next.ID)).To(Succeed())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user