feat: notifications say what changed and alert once: a grouped notice names the tracks, grows without re-alerting, and a phone pile lists its titles (M542 #6146-#6151)
release / govulncheck (push) Successful in 14s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m33s
release / android (push) Failing after 1m42s
release / integration (push) Failing after 4m42s
release / Build signed APK (releases and dev) (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 14s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m33s
release / android (push) Failing after 1m42s
release / integration (push) Failing after 4m42s
release / Build signed APK (releases and dev) (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
- An update to a grouped notice keeps its arrival time and email state, so the phone and the email no longer go off again each time it grows. - Notices carry the names of what changed (newest ten), shown as three and "and N more": tracks still missing after the scan's move/replacement fold, duplicate groups new to a sweep, songs merged automatically, and the track and listener a playback error was for. - Duplicates found counts only the groups new to that sweep; playback errors count reports, not the unresolved total. - A scan failure says what stopped and links to Admin > Library. - Android: a pile of more than three alerts lists the newest five titles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||||
syncpkg "git.fabledsword.com/bvandeusen/minstrel/internal/sync"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/words"
|
||||
)
|
||||
|
||||
// Duplicate resolver (M498 #5435, #5437; M502 #5517).
|
||||
@@ -149,6 +148,7 @@ func ResolveDuplicates(
|
||||
|
||||
// Merges before links, so a rip merged away is not linked first.
|
||||
merged := map[pgtype.UUID]bool{}
|
||||
var mergedNames []string
|
||||
for _, g := range groups {
|
||||
if res.Merged >= resolveMergeCap {
|
||||
break
|
||||
@@ -167,6 +167,9 @@ func ResolveDuplicates(
|
||||
}
|
||||
merged[g.id] = true
|
||||
res.Merged++
|
||||
if len(mergedNames) < notifyItems {
|
||||
mergedNames = append(mergedNames, TrackLabel(g.members[0].ArtistName, g.members[0].Title))
|
||||
}
|
||||
}
|
||||
|
||||
linked, err := linkCrossRelease(ctx, pool, logger, groups, merged)
|
||||
@@ -177,8 +180,7 @@ func ResolveDuplicates(
|
||||
|
||||
if res.Merged > 0 {
|
||||
notifyAdmins(ctx, notifications.KindDuplicatesResolved, notifications.Payload{
|
||||
Count: int64(res.Merged),
|
||||
Detail: "Merged " + words.Count(res.Merged, "duplicate copy", "duplicate copies") + ".",
|
||||
Count: int64(res.Merged), Items: mergedNames,
|
||||
})
|
||||
}
|
||||
return res, nil
|
||||
|
||||
@@ -112,25 +112,26 @@ func runDuplicateSweep(
|
||||
return res, runErr
|
||||
}
|
||||
|
||||
// notifyNewDuplicates tells admins when a sweep proposed a group it had not
|
||||
// proposed before (M489), counting every proposal awaiting review. A sweep
|
||||
// that only re-finds known groups says nothing, so reading the notice once
|
||||
// is enough until something new turns up.
|
||||
// notifyNewDuplicates tells admins when a sweep proposed groups it had not
|
||||
// proposed before (M489), counting and naming those (M542). A sweep that only
|
||||
// re-finds known groups says nothing, so reading the notice once is enough
|
||||
// until something new turns up.
|
||||
func notifyNewDuplicates(ctx context.Context, q *dbq.Queries, sweepStarted pgtype.Timestamptz, logger *slog.Logger) {
|
||||
fresh, err := q.CountDuplicateGroupsDetectedSince(ctx, sweepStarted)
|
||||
fresh, err := q.ListDuplicateGroupsDetectedSince(ctx, dbq.ListDuplicateGroupsDetectedSinceParams{
|
||||
Since: sweepStarted, N: notifyItems,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Warn("duplicate sweep: counting new proposals failed", "err", err)
|
||||
logger.Warn("duplicate sweep: listing new proposals failed", "err", err)
|
||||
return
|
||||
}
|
||||
if fresh == 0 {
|
||||
if len(fresh) == 0 {
|
||||
return
|
||||
}
|
||||
pending, err := q.CountPendingDuplicateGroups(ctx)
|
||||
if err != nil {
|
||||
logger.Warn("duplicate sweep: counting pending proposals failed", "err", err)
|
||||
return
|
||||
items := make([]string, 0, len(fresh))
|
||||
for _, g := range fresh {
|
||||
items = append(items, TrackLabel(g.ArtistName, g.Title))
|
||||
}
|
||||
notifyAdmins(ctx, notifications.KindDuplicatesFound, notifications.Payload{Count: pending})
|
||||
notifyAdmins(ctx, notifications.KindDuplicatesFound, notifications.Payload{Count: fresh[0].Total, Items: items})
|
||||
}
|
||||
|
||||
func sweepDuplicates(
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||||
)
|
||||
|
||||
@@ -34,6 +35,42 @@ func notifyAdmins(ctx context.Context, kind notifications.Kind, p notifications.
|
||||
n.NotifyLogged(ctx, kind, notifications.ToAdmins(pgtype.UUID{}), p.Map())
|
||||
}
|
||||
|
||||
// notifyItems is how many names a notice carries; the notifications package
|
||||
// keeps the newest ten across a coalesced burst.
|
||||
const notifyItems = 10
|
||||
|
||||
// TrackLabel names a track as a notice does: "Artist – Title", or the title
|
||||
// alone when the artist is unknown.
|
||||
func TrackLabel(artist, title string) string {
|
||||
if artist == "" {
|
||||
return title
|
||||
}
|
||||
return artist + " – " + title
|
||||
}
|
||||
|
||||
// notifyStillMissing tells admins which of the tracks a scan marked missing
|
||||
// are still gone after it adopted moves and folded replacements (M542). A
|
||||
// marked track the scan healed is not news: reporting it is what made a
|
||||
// quality upgrade read as lost music.
|
||||
func (s *Scanner) notifyStillMissing(ctx context.Context, marked []pgtype.UUID) {
|
||||
if len(marked) == 0 || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
rows, err := dbq.New(s.pool).ListStillMissingTrackLabels(ctx, marked)
|
||||
if err != nil {
|
||||
s.logger.Warn("library scan: listing missing tracks for the notice failed", "err", err)
|
||||
return
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
return
|
||||
}
|
||||
items := make([]string, 0, min(len(rows), notifyItems))
|
||||
for _, r := range rows[:min(len(rows), notifyItems)] {
|
||||
items = append(items, TrackLabel(r.ArtistName, r.Title))
|
||||
}
|
||||
notifyAdmins(ctx, notifications.KindTracksMissing, notifications.Payload{Count: int64(len(rows)), Items: items})
|
||||
}
|
||||
|
||||
// notifyScanFinished tells admins a scan run ended in error. A scan cut short
|
||||
// by shutdown is not a failure anyone needs telling about.
|
||||
func notifyScanFinished(ctx context.Context, errMsg string) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
@@ -36,6 +37,7 @@ type notice struct {
|
||||
kind string
|
||||
count int64
|
||||
body string
|
||||
items []string
|
||||
}
|
||||
|
||||
func unreadNotices(t *testing.T, pool *pgxpool.Pool, user dbq.User) []notice {
|
||||
@@ -55,7 +57,7 @@ func unreadNotices(t *testing.T, pool *pgxpool.Pool, user dbq.User) []notice {
|
||||
if err := json.Unmarshal(r.Payload, &p); err != nil {
|
||||
t.Fatalf("payload: %v", err)
|
||||
}
|
||||
out = append(out, notice{kind: r.Kind, count: p.Count, body: p.Detail})
|
||||
out = append(out, notice{kind: r.Kind, count: p.Count, body: p.Detail, items: p.Items})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -86,31 +88,70 @@ func TestNotifyScanFinished_FailuresCoalesceAndShutdownIsSilent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileMissing_NotifiesAdminsWithARunningCount(t *testing.T) {
|
||||
// M542: reconcile only records what it marked. The scan tells admins after
|
||||
// it has adopted moves and folded replacements, so a file it marked and then
|
||||
// healed is never reported as lost.
|
||||
func TestReconcileMissing_RecordsTheMarksWithoutNotifying(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
admin := notifyingAdmin(t, pool)
|
||||
s := testScanner(t, populatedRoot(t))
|
||||
|
||||
// Two scans, each losing 2 of 10 tracks (under the mark cap).
|
||||
for pass := 0; pass < 2; pass++ {
|
||||
rows := make([]dbq.ListTrackPathsForReconcileRow, 0, 10)
|
||||
seen := map[string]struct{}{}
|
||||
for i := 0; i < 10; i++ {
|
||||
p := fmt.Sprintf("/music/pass-%d-%02d.mp3", pass, i)
|
||||
rows = append(rows, row(byte(pass*10+i), p, false))
|
||||
if i >= 2 {
|
||||
seen[p] = struct{}{}
|
||||
}
|
||||
}
|
||||
var stats Stats
|
||||
if err := s.reconcileMissing(context.Background(), &fakeReconciler{rows: rows}, seen, &stats); err != nil {
|
||||
t.Fatalf("reconcile pass %d: %v", pass, err)
|
||||
rows := make([]dbq.ListTrackPathsForReconcileRow, 0, 10)
|
||||
seen := map[string]struct{}{}
|
||||
for i := 0; i < 10; i++ {
|
||||
p := fmt.Sprintf("/music/%02d.mp3", i)
|
||||
rows = append(rows, row(byte(i), p, false))
|
||||
if i >= 2 {
|
||||
seen[p] = struct{}{}
|
||||
}
|
||||
}
|
||||
var stats Stats
|
||||
if err := s.reconcileMissing(context.Background(), &fakeReconciler{rows: rows}, seen, &stats); err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if len(stats.marked) != 2 {
|
||||
t.Errorf("marked %d tracks; want the 2 the walk did not see", len(stats.marked))
|
||||
}
|
||||
if got := unreadNotices(t, pool, admin); len(got) != 0 {
|
||||
t.Fatalf("reconcile notified before the scan could heal anything: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyStillMissing_NamesOnlyTheTracksStillGone(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
admin := notifyingAdmin(t, pool)
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
dir := t.TempDir()
|
||||
first, album, artist := seedTrack(t, pool, filepath.Join(dir, "a.mp3"))
|
||||
second, err := q.UpsertTrack(ctx, dbq.UpsertTrackParams{
|
||||
Title: "Another Track", AlbumID: album.ID, ArtistID: artist.ID,
|
||||
DurationMs: 1000, FilePath: filepath.Join(dir, "b.mp3"), FileSize: 100, FileFormat: "mp3",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The scan marked both; the second came back (a move it adopted).
|
||||
marked := []pgtype.UUID{first.ID, second.ID}
|
||||
if _, err := q.MarkTracksMissing(ctx, []pgtype.UUID{first.ID}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s := New(pool, slog.New(slog.NewTextHandler(io.Discard, nil)), nil, nil)
|
||||
s.notifyStillMissing(ctx, marked)
|
||||
got := unreadNotices(t, pool, admin)
|
||||
if len(got) != 1 || got[0].kind != string(notifications.KindTracksMissing) || got[0].count != 4 {
|
||||
t.Fatalf("notices = %+v, want one tracks_missing counting 4", got)
|
||||
if len(got) != 1 || got[0].kind != string(notifications.KindTracksMissing) || got[0].count != 1 ||
|
||||
len(got[0].items) != 1 || got[0].items[0] != "Delete Test Artist – Delete Test Track" {
|
||||
t.Fatalf("notices = %+v, want one tracks_missing naming the one track still gone", got)
|
||||
}
|
||||
|
||||
// Nothing still gone: nothing to say.
|
||||
if _, err := q.MarkAllNotificationsRead(ctx, dbq.MarkAllNotificationsReadParams{UserID: admin.ID}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.notifyStillMissing(ctx, []pgtype.UUID{second.ID})
|
||||
if got := unreadNotices(t, pool, admin); len(got) != 0 {
|
||||
t.Fatalf("a healed track was reported: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,8 +200,9 @@ func TestDuplicateSweep_NotifiesOnlyWhenSomethingNewIsProposed(t *testing.T) {
|
||||
pair("first", 1, 100)
|
||||
sweep()
|
||||
got := unreadNotices(t, pool, admin)
|
||||
if len(got) != 1 || got[0].kind != string(notifications.KindDuplicatesFound) || got[0].count != 1 {
|
||||
t.Fatalf("after the first sweep notices = %+v, want one duplicates_found counting 1", got)
|
||||
if len(got) != 1 || got[0].kind != string(notifications.KindDuplicatesFound) || got[0].count != 1 ||
|
||||
len(got[0].items) != 1 || got[0].items[0] != "Delete Test Artist – first" {
|
||||
t.Fatalf("after the first sweep notices = %+v, want one duplicates_found naming the first pair", got)
|
||||
}
|
||||
|
||||
// Read, then swept again with nothing new: no reminder.
|
||||
@@ -170,11 +212,11 @@ func TestDuplicateSweep_NotifiesOnlyWhenSomethingNewIsProposed(t *testing.T) {
|
||||
t.Fatalf("a sweep that found nothing new notified: %+v", got)
|
||||
}
|
||||
|
||||
// A new pair is news, and the count is everything awaiting review.
|
||||
// A new pair is news, and the notice is about it alone: the first was read.
|
||||
pair("second", 2, 200)
|
||||
sweep()
|
||||
got = unreadNotices(t, pool, admin)
|
||||
if len(got) != 1 || got[0].count != 2 {
|
||||
t.Fatalf("after a new pair notices = %+v, want one counting 2", got)
|
||||
if len(got) != 1 || got[0].count != 1 || len(got[0].items) != 1 || got[0].items[0] != "Delete Test Artist – second" {
|
||||
t.Fatalf("after a new pair notices = %+v, want one naming only the new pair", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||||
syncpkg "git.fabledsword.com/bvandeusen/minstrel/internal/sync"
|
||||
)
|
||||
|
||||
@@ -129,9 +128,9 @@ func (s *Scanner) reconcileMissing(
|
||||
// this line.
|
||||
s.logger.Warn("library scan: tracks marked missing (files not found)",
|
||||
"count", n, "library_total", len(rows))
|
||||
if n > 0 {
|
||||
notifyAdmins(ctx, notifications.KindTracksMissing, notifications.Payload{Count: n})
|
||||
}
|
||||
// Admins are told after the scan has adopted moves and folded
|
||||
// replacements, about the ones still gone (notifyStillMissing).
|
||||
stats.marked = toMark
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,10 @@ type Stats struct {
|
||||
// Only a full Scan sets these — see reconcileMissing.
|
||||
Missing int `json:"missing"`
|
||||
Restored int `json:"restored"`
|
||||
// marked are the tracks this scan's reconcile marked missing, so the scan
|
||||
// can tell admins which of them are still gone once it has adopted moves
|
||||
// and folded replacements (M542).
|
||||
marked []pgtype.UUID
|
||||
}
|
||||
|
||||
type Scanner struct {
|
||||
@@ -198,6 +202,9 @@ func (s *Scanner) Scan(ctx context.Context, progressCb func(Stats)) (Stats, erro
|
||||
if _, err := PairMissingTracks(ctx, s.pool, s.logger); err != nil && ctx.Err() == nil {
|
||||
s.logger.Warn("library scan: missing-pair pass failed", "err", err)
|
||||
}
|
||||
// Told only now, so a file that moved or was upgraded, which this scan
|
||||
// marked and then healed, is not reported as lost.
|
||||
s.notifyStillMissing(ctx, stats.marked)
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@ type LibraryStageTallies struct {
|
||||
Restored int `json:"restored"`
|
||||
}
|
||||
|
||||
func (st Stats) tallies() LibraryStageTallies {
|
||||
return LibraryStageTallies{
|
||||
Scanned: st.Scanned, Added: st.Added, Updated: st.Updated, Skipped: st.Skipped,
|
||||
Errored: st.Errored, Missing: st.Missing, Restored: st.Restored,
|
||||
}
|
||||
}
|
||||
|
||||
// MBIDBackfillStageTallies wires BackfillMBIDsResult into the scan_runs jsonb column.
|
||||
type MBIDBackfillStageTallies struct {
|
||||
Processed int `json:"processed"`
|
||||
@@ -105,7 +112,7 @@ func RunScan(
|
||||
var lastStats Stats
|
||||
libPub := newStagePublisher(ctx, 500, time.Second,
|
||||
func() []byte {
|
||||
blob, _ := json.Marshal(LibraryStageTallies(lastStats))
|
||||
blob, _ := json.Marshal(lastStats.tallies())
|
||||
return blob
|
||||
},
|
||||
func(blob []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user