mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
* feat(artwork): record the resolution trace so explain works without --live The worker never attached a ChainTrace, so `artwork explain` had to re-walk the priority chain at CLI time. That reconstruction could disagree with what actually happened, and without --live it could not report the external tier at all. The worker now traces every acquisition and stores it. `explain` reads the stored trace by default and reports when it was recorded; --live re-walks and calls the agents. Disc artwork keeps no row, so it always walks live. A chain trace alone would have explained almost nothing about failures: six of the seven ways an item can fail happen after the chain has already picked a winner. The trace now covers those stages too, and has somewhere to live when they fail: the retrying queue row carries the last failure, and the state row keeps it in last_failure once the retry budget is spent and the queue row is deleted. Measured on a copy of a 682MB / 43.6k-item library: +9.7MB (+1.4%). No row crosses the WITHOUT ROWID overflow threshold, so list hydration is unchanged; only full scans of item_artwork, which no request performs, read more pages. * test(artwork): pin the give-up ordering that keeps a failure for unresolved items recordGiveUp updates an existing row, and for a kind with a recheck path that row is only created moments earlier by the absent settle. Recording before the settle would lose the failure for every item that never resolved, with nothing to catch it. * refactor(artwork): tighten the trace code after review Four fixes worth taking: The doc comments on ChainTrace and chainState.trace still said the worker never attaches a trace and resolution stays allocation-free — the exact invariant this branch reverses. explain's report field meant both "the chain shown was walked just now" and "go out for real", and was being passed to loadPluginAgents, which --live documents as the only thing that may open external connections. Renamed to `walked` and restored explainLive as the sole input to that decision. A stored Detail is an error string on the failure paths, with no bound. The measured "no row reaches the WITHOUT ROWID overflow limit" only holds while it is bounded, so cap it at 200 runes. offlineGate was a factory returning a constant closure; make it a plain gateFunc like its sibling passthroughGate. Collapse five copies of the age-a-queue-row loop in the worker tests into one helper. * refactor(artwork): drop the offline explain walk, now that traces are stored `artwork explain` reported the external tier without calling it, so a diagnostic could not add load to a provider already rate-limiting us. Reading the stored trace answers that better: it reports what the agents actually returned, not what would be tried. Nothing could reach the offline gate any more. It was installed only for a walk with --live unset, which now happens for disc artwork alone, and disc rejects the external candidate before any gate call. That made the gate, its sentinel error, the would-try outcome and two of explain's verdicts unreachable. Removes offlineGate, errOfflineSkipped, OutcomeWouldTry, the NewTracingResolver live parameter and the CreateArtworkResolver argument threaded through wire. Verified against a copy of a real library: disc artwork with "external" first in DiscArtPriority and external services enabled still records the skip and issues no agent call. * fix(artwork): make explain's no-network guarantee structural, not incidental Serving falls back disc -> album and track -> disc -> album. The resolver layer explain uses has no such fallback today, so dropping the offline gate did not leak. But the guarantee rested on which chains happen to lack an external tier, and the serving layer already shows the fallback shape someone could mirror. Without --live the tracing resolver is now built with no agents at all, so no chain and no fallback added later can reach a provider. That is stronger than the gate it replaces, which only intercepted the call. The test pins it against exactly that regression: with the guard removed and the serving fallback mirrored into resolveDisc, it fails. * refactor(artwork): trim the trace plumbing EncodeTrace was exported for nobody: only this package writes traces, and cmd reads them. It becomes a ChainTrace method, which also drops the copy Steps made for a caller that only wanted to serialize. explain's report carried queuedSteps and failureSteps, both pure functions of the queue and state rows already in the struct, which let a test set the two out of step with each other. formatExplain derives them, as it already does for every other display value. The trace row format and its tabwriter empty-cell rule lived in two places, and the "nothing was ever recorded" predicate in three. * fix(artwork): clear the queue trace on a fresh re-enqueue Enqueue's conflict clause reset attempts to 0 but left the new trace column, so after a scan or refresh re-enqueued a previously-failed item artwork explain showed "Attempts: 0" next to the prior lifecycle's "Last attempt failed" trace. Clear trace in Enqueue (a fresh lifecycle has no last attempt); EnqueuePreservingBackoff still keeps it. * fix(artwork): treat a processing-stage error as indeterminate in explain A read/hash/decode/store failure records an OutcomeError step and writes an absent row, but explainResult only mapped external errors and unreadable candidates to indeterminate, so the default verdict read "not resolved" — presenting a processing failure as a definitive miss. The worker retries these exactly as it retries an unreadable candidate, so classify any OutcomeError as indeterminate too. * fix(artwork): record a trace step when a chainless resolver faults Playlist and radio resolvers walk no priority chain, so a fault (unreadable upload/sidecar, or an m3u fetch error with no grid) returned localError/extError without recording any trace step. The attempt then encoded [], leaving artwork explain with an empty "Last attempt failed" and "Gave up after". Record a fallback step in the faulted-no-image branch when nothing else did, and carry the source label through resolveLocalFile so the step can name it. * fix(artwork): trace the m3u failure at its source, not via the empty guard A playlist's grid sampling records album-chain steps into the shared trace, so the processor's empty-trace fallback no longer fires when the m3u remote image fetch failed — the error that forced the retry was omitted from explain. Record it where it happens, in resolvePlaylist's external step, as external:m3u. * test(artwork): skip the chainless-fault spec on Windows The spec provokes an open fault with a non-directory parent, but Windows maps that to a not-exist error, so localError is never set and the item resolves absent instead of failed. The sibling failed-on-unreadable-upload spec skips Windows for the same class of reason. * fix(artwork): don't label an absent empty-chain row as pre-tracing explain reported "resolved before traces were recorded" for any stored row with an empty chain, but an empty CoverArtPriority records a real, empty [] chain and resolves absent. A recorded resolution that finds an image always records its winning candidate, so only a row with a hash and no chain predates tracing; split on the hash and report an absent empty chain plainly instead. * fix(db): retimestamp the artwork trace migration after rebase master merged a 2026-08-18 migration, so the original 2026-08-16 timestamp is now older than the newest on the base branch and Goose would silently skip it on an already-upgraded database. Bumped past it; the SQL is unchanged. * fix(artwork): keep the m3u error detail in the trace The m3u trace step recorded OutcomeError with no detail because resolveExternalStep collapsed the gate's error to a bool, so explain showed only "external:m3u error -" and could not tell a timeout from an HTTP error or an open breaker. Return the error (normalizing not-found to nil so it stays a definitive miss, not a failure) and store its message as the step detail; encodeSteps already bounds it. * docs(artwork): note the give-up write relies on serial draining recordGiveUp writes last_failure unconditionally; that is only correct because the drain resolves each item serially, so no concurrent success can store artwork between the write and the queue delete. Record the invariant at the call site.
294 lines
13 KiB
Go
294 lines
13 KiB
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/pocketbase/dbx"
|
|
)
|
|
|
|
func clearArtworkTables() {
|
|
db := GetDBXBuilder()
|
|
for _, t := range []string{"artwork_queue", "item_artwork", "artwork"} {
|
|
_, err := db.NewQuery("DELETE FROM " + t).Execute()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
}
|
|
}
|
|
|
|
var _ = Describe("ArtworkRepository", func() {
|
|
var repo model.ArtworkRepository
|
|
|
|
BeforeEach(func() {
|
|
clearArtworkTables()
|
|
DeferCleanup(clearArtworkTables)
|
|
repo = NewArtworkRepository(context.Background(), GetDBXBuilder())
|
|
})
|
|
|
|
Context("resolution traces", func() {
|
|
const traceJSON = `[{"c":"cover.*","o":"hit"}]`
|
|
|
|
It("round-trips the trace with the state row", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "t1",
|
|
ImageType: model.ImageTypePrimary, Hash: "h1", Trace: traceJSON})).To(Succeed())
|
|
|
|
got, err := repo.GetItemArtwork(model.KindAlbumArtwork, "t1", model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.Trace).To(Equal(traceJSON))
|
|
Expect(got.LastFailure).To(BeEmpty())
|
|
})
|
|
|
|
It("replaces the trace when the item is resolved again", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "t2",
|
|
ImageType: model.ImageTypePrimary, Trace: traceJSON})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "t2",
|
|
ImageType: model.ImageTypePrimary, Trace: `[{"c":"embedded","o":"hit"}]`})).To(Succeed())
|
|
|
|
got, _ := repo.GetItemArtwork(model.KindAlbumArtwork, "t2", model.ImageTypePrimary)
|
|
Expect(got.Trace).To(Equal(`[{"c":"embedded","o":"hit"}]`))
|
|
})
|
|
|
|
It("records a last failure on an existing row", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "t3",
|
|
ImageType: model.ImageTypePrimary, Hash: "h3"})).To(Succeed())
|
|
|
|
Expect(repo.PutLastFailure(model.KindAlbumArtwork, "t3", model.ImageTypePrimary,
|
|
`[{"c":"decode","o":"error"}]`)).To(Succeed())
|
|
|
|
got, _ := repo.GetItemArtwork(model.KindAlbumArtwork, "t3", model.ImageTypePrimary)
|
|
Expect(got.LastFailure).To(Equal(`[{"c":"decode","o":"error"}]`))
|
|
Expect(got.Hash).To(Equal("h3"), "recording a failure must not disturb the served artwork")
|
|
})
|
|
|
|
// Inserting here would write hash='', which every reader treats as a settled absent.
|
|
It("never creates a row for an item that has no state", func() {
|
|
Expect(repo.PutLastFailure(model.KindAlbumArtwork, "ghost", model.ImageTypePrimary,
|
|
`[{"c":"decode","o":"error"}]`)).To(Succeed())
|
|
|
|
_, err := repo.GetItemArtwork(model.KindAlbumArtwork, "ghost", model.ImageTypePrimary)
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
})
|
|
})
|
|
|
|
Context("image identity", func() {
|
|
It("stores and retrieves an artwork by hash", func() {
|
|
a := &model.Artwork{Hash: "abc123", Mime: "image/jpeg", Width: 500, Height: 500, SizeBytes: 1234, BlurHash: "LKO2?U%2Tw=w"}
|
|
Expect(repo.PutImage(a)).To(Succeed())
|
|
|
|
got, err := repo.GetImage("abc123")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.Mime).To(Equal("image/jpeg"))
|
|
Expect(got.BlurHash).To(Equal("LKO2?U%2Tw=w"))
|
|
Expect(got.CreatedAt).ToNot(BeZero())
|
|
})
|
|
|
|
It("round-trips the thumbhash alongside the blurhash", func() {
|
|
a := &model.Artwork{Hash: "both1", Mime: "image/jpeg", BlurHash: "LKO2?U%2Tw=w",
|
|
ThumbHash: "1QcSHQRnh493V4dIh4eXh1h4kJUI", DominantColor: "#336699"}
|
|
Expect(repo.PutImage(a)).To(Succeed())
|
|
|
|
got, err := repo.GetImage("both1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.BlurHash).To(Equal("LKO2?U%2Tw=w"))
|
|
Expect(got.ThumbHash).To(Equal("1QcSHQRnh493V4dIh4eXh1h4kJUI"))
|
|
Expect(got.DominantColor).To(Equal("#336699"))
|
|
})
|
|
|
|
It("overwrites the thumbhash on re-acquisition", func() {
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "th2", Mime: "image/png", ThumbHash: "first", DominantColor: "#111111"})).To(Succeed())
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "th2", Mime: "image/png", ThumbHash: "second", DominantColor: "#222222"})).To(Succeed())
|
|
|
|
got, err := repo.GetImage("th2")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.ThumbHash).To(Equal("second"))
|
|
Expect(got.DominantColor).To(Equal("#222222"))
|
|
})
|
|
|
|
It("is idempotent on Put (upsert by hash)", func() {
|
|
a := &model.Artwork{Hash: "dup1", Mime: "image/png"}
|
|
Expect(repo.PutImage(a)).To(Succeed())
|
|
a.BlurHash = "XYZ"
|
|
Expect(repo.PutImage(a)).To(Succeed())
|
|
got, _ := repo.GetImage("dup1")
|
|
Expect(got.BlurHash).To(Equal("XYZ"))
|
|
})
|
|
|
|
It("refreshes created_at when reacquiring an existing hash", func() {
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "reacq", Mime: "image/jpeg"})).To(Succeed())
|
|
_, err := GetDBXBuilder().NewQuery("UPDATE artwork SET created_at={:t} WHERE hash='reacq'").
|
|
Bind(dbx.Params{"t": "2000-01-01 00:00:00"}).Execute()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "reacq", Mime: "image/png"})).To(Succeed())
|
|
|
|
got, err := repo.GetImage("reacq")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.CreatedAt).To(BeTemporally(">", time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)))
|
|
})
|
|
|
|
It("returns ErrNotFound for a missing hash", func() {
|
|
_, err := repo.GetImage("nope")
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
})
|
|
|
|
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.GetMimeByHash()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(mimes).To(HaveKeyWithValue("all1", "image/jpeg"))
|
|
Expect(mimes).To(HaveKeyWithValue("all2", "image/png"))
|
|
})
|
|
|
|
It("deletes only unreferenced rows older than the cutoff, reporting the count", func() {
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "d1", Mime: "image/jpeg"})).To(Succeed())
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "dref", Mime: "image/jpeg"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "a1",
|
|
ImageType: model.ImageTypePrimary, Hash: "dref", Source: "folder"})).To(Succeed())
|
|
|
|
Expect(repo.PurgeOrphans(time.Now().Add(time.Minute))).To(BeNumerically("==", 1))
|
|
|
|
_, err := repo.GetImage("d1")
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
_, err = repo.GetImage("dref")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("spares an unreferenced row younger than the cutoff", func() {
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "young", Mime: "image/jpeg"})).To(Succeed())
|
|
Expect(repo.PurgeOrphans(time.Now().Add(-time.Hour))).To(BeNumerically("==", 0))
|
|
_, err := repo.GetImage("young")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("dangling state cleanup", func() {
|
|
It("purges item_artwork rows per kind whose entity no longer exists, summing counts", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: albumSgtPeppers.ID, ImageType: model.ImageTypePrimary, Hash: "keepAl"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "no-such-album", ImageType: model.ImageTypePrimary, Hash: "danglingAl"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ar", ItemID: artistKraftwerk.ID, ImageType: model.ImageTypePrimary, Hash: "keepAr"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ar", ItemID: "no-such-artist", ImageType: model.ImageTypePrimary, Hash: "danglingAr"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "pl", ItemID: plsBest.ID, ImageType: model.ImageTypePrimary, Hash: "keepPl"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "pl", ItemID: "no-such-playlist", ImageType: model.ImageTypePrimary, Hash: "danglingPl"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ra", ItemID: radioWithHomePage.ID, ImageType: model.ImageTypePrimary, Hash: "keepRa"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ra", ItemID: "no-such-radio", ImageType: model.ImageTypePrimary, Hash: "danglingRa"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "mf", ItemID: songDayInALife.ID, ImageType: model.ImageTypePrimary, Hash: "keepMf"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "mf", ItemID: "no-such-mediafile", ImageType: model.ImageTypePrimary, Hash: "danglingMf"})).To(Succeed())
|
|
|
|
purged, err := repo.PurgeDanglingItems()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(purged).To(Equal(int64(5)))
|
|
|
|
for _, kept := range []model.ItemArtwork{
|
|
{ItemKind: "al", ItemID: albumSgtPeppers.ID},
|
|
{ItemKind: "ar", ItemID: artistKraftwerk.ID},
|
|
{ItemKind: "pl", ItemID: plsBest.ID},
|
|
{ItemKind: "ra", ItemID: radioWithHomePage.ID},
|
|
{ItemKind: "mf", ItemID: songDayInALife.ID},
|
|
} {
|
|
k, _ := model.ParseKind(kept.ItemKind)
|
|
_, err := repo.GetItemArtwork(k, kept.ItemID, model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
}
|
|
for _, gone := range []model.ItemArtwork{
|
|
{ItemKind: "al", ItemID: "no-such-album"},
|
|
{ItemKind: "ar", ItemID: "no-such-artist"},
|
|
{ItemKind: "pl", ItemID: "no-such-playlist"},
|
|
{ItemKind: "ra", ItemID: "no-such-radio"},
|
|
{ItemKind: "mf", ItemID: "no-such-mediafile"},
|
|
} {
|
|
k, _ := model.ParseKind(gone.ItemKind)
|
|
_, err := repo.GetItemArtwork(k, gone.ItemID, model.ImageTypePrimary)
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("item state", func() {
|
|
It("upserts and reads state, including per-item provenance", func() {
|
|
ia := &model.ItemArtwork{ItemKind: "al", ItemID: "al1", ImageType: model.ImageTypePrimary,
|
|
Hash: "h1", Source: "folder", SourcePath: "/music/a/cover.jpg", RefMtime: 111, AttemptedAt: time.Now()}
|
|
Expect(repo.PutItemArtwork(ia)).To(Succeed())
|
|
ia.Source = "embedded"
|
|
ia.SourcePath = "/music/a/track.mp3"
|
|
ia.RefMtime = 222
|
|
Expect(repo.PutItemArtwork(ia)).To(Succeed())
|
|
|
|
got, err := repo.GetItemArtwork(model.KindAlbumArtwork, "al1", model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.Source).To(Equal("embedded"))
|
|
Expect(got.SourcePath).To(Equal("/music/a/track.mp3"))
|
|
Expect(got.RefMtime).To(Equal(int64(222)))
|
|
Expect(got.UpdatedAt).ToNot(BeZero())
|
|
})
|
|
|
|
It("defaults attempted_at to now when unset", func() {
|
|
before := time.Now().Add(-time.Second)
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ar", ItemID: "noattempt",
|
|
ImageType: model.ImageTypePrimary, Hash: ""})).To(Succeed())
|
|
got, err := repo.GetItemArtwork(model.KindArtistArtwork, "noattempt", model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.AttemptedAt).To(BeTemporally(">", before))
|
|
})
|
|
|
|
It("represents known-absent as empty hash", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "ar", ItemID: "ar1",
|
|
ImageType: model.ImageTypePrimary, Hash: "", AttemptedAt: time.Now()})).To(Succeed())
|
|
got, err := repo.GetItemArtwork(model.KindArtistArtwork, "ar1", model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(got.Hash).To(BeEmpty())
|
|
})
|
|
|
|
It("hydrates a page in one batch, including blurhash, dimensions and absence", func() {
|
|
Expect(repo.PutImage(&model.Artwork{Hash: "h9", Mime: "image/jpeg", BlurHash: "BH9",
|
|
DominantColor: "#abcdef", Width: 1200, Height: 800})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "x1", ImageType: model.ImageTypePrimary, Hash: "h9", Source: "folder"})).To(Succeed())
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "al", ItemID: "x2", ImageType: model.ImageTypePrimary, Hash: "", Source: ""})).To(Succeed())
|
|
|
|
info, err := repo.GetInfoForItems(model.KindAlbumArtwork, []string{"x1", "x2", "x3"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(info).To(HaveLen(2))
|
|
Expect(info["x1"].Hash).To(Equal("h9"))
|
|
Expect(info["x1"].BlurHash).To(Equal("BH9"))
|
|
Expect(info["x1"].DominantColor).To(Equal("#abcdef"))
|
|
Expect(info["x1"].Width).To(Equal(1200))
|
|
Expect(info["x1"].Height).To(Equal(800))
|
|
Expect(info["x1"].Absent()).To(BeFalse())
|
|
Expect(info["x2"].Absent()).To(BeTrue())
|
|
_, unresolved := info["x3"]
|
|
Expect(unresolved).To(BeFalse())
|
|
})
|
|
|
|
It("deletes all rows for a single item", func() {
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "pl", ItemID: "p1", ImageType: model.ImageTypePrimary, Hash: "h1"})).To(Succeed())
|
|
Expect(repo.DeleteForItems(model.KindPlaylistArtwork, []string{"p1"})).To(Succeed())
|
|
_, err := repo.GetItemArtwork(model.KindPlaylistArtwork, "p1", model.ImageTypePrimary)
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
})
|
|
|
|
It("deletes rows for many items in chunks, leaving others untouched", func() {
|
|
const n = artworkBatchSize + 5
|
|
ids := make([]string, n)
|
|
for i := range n {
|
|
id := fmt.Sprintf("mf-%d", i)
|
|
ids[i] = id
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "mf", ItemID: id, ImageType: model.ImageTypePrimary, Hash: "h1"})).To(Succeed())
|
|
}
|
|
Expect(repo.PutItemArtwork(&model.ItemArtwork{ItemKind: "mf", ItemID: "keep", ImageType: model.ImageTypePrimary, Hash: "h1"})).To(Succeed())
|
|
|
|
Expect(repo.DeleteForItems(model.KindMediaFileArtwork, ids)).To(Succeed())
|
|
|
|
for _, id := range ids {
|
|
_, err := repo.GetItemArtwork(model.KindMediaFileArtwork, id, model.ImageTypePrimary)
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
}
|
|
kept, err := repo.GetItemArtwork(model.KindMediaFileArtwork, "keep", model.ImageTypePrimary)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(kept.ItemID).To(Equal("keep"))
|
|
})
|
|
})
|
|
})
|