refactor: drop code nothing calls, and the sync log rows no app reads (#8002)
release / go (push) Successful in 1m56s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m20s
release / Build signed APK (push) Successful in 4m52s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m56s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m20s
release / Build signed APK (push) Successful in 4m52s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
- library.ProbeDurationMs and IsAudioFile, and db.MigrationsFS, had no callers. - The delta sync logged and hydrated like and playlist changes on every like, playlist edit and duplicate merge, including a GetPlaylistsByIDs query per sync. Android applies only artists, albums and tracks, and the web doesn't sync; likes and playlists reach both through their own endpoints and live events. The like and playlist-entry deletes also went to every caller unscoped, user ids included. They are no longer written or served, and migration 0112 clears the rows already logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -170,10 +170,6 @@ func (s *Service) CreateWithID(ctx context.Context, userID, id pgtype.UUID, name
|
||||
case err != nil:
|
||||
return nil, fmt.Errorf("create playlist: %w", err)
|
||||
}
|
||||
if err := syncpkg.LogChange(ctx, s.pool, syncpkg.EntityPlaylist,
|
||||
syncpkg.FormatUUID(row.ID), syncpkg.OpUpsert); err != nil {
|
||||
s.logger.Warn("playlists: LogChange create failed", "playlist_id", row.ID, "err", err)
|
||||
}
|
||||
s.publish("playlist.created", userID, row.ID)
|
||||
// CreatePlaylist returns the playlist's own columns; the owner's
|
||||
// username comes from GetPlaylist's join.
|
||||
@@ -334,10 +330,6 @@ func (s *Service) Update(ctx context.Context, callerID, playlistID pgtype.UUID,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update playlist: %w", err)
|
||||
}
|
||||
if err := syncpkg.LogChange(ctx, s.pool, syncpkg.EntityPlaylist,
|
||||
syncpkg.FormatUUID(updated.ID), syncpkg.OpUpsert); err != nil {
|
||||
s.logger.Warn("playlists: LogChange update failed", "playlist_id", updated.ID, "err", err)
|
||||
}
|
||||
s.publish("playlist.updated", callerID, playlistID)
|
||||
full, err := q.GetPlaylist(ctx, updated.ID)
|
||||
if err != nil {
|
||||
@@ -361,10 +353,6 @@ func (s *Service) Delete(ctx context.Context, callerID, playlistID pgtype.UUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete playlist: %w", err)
|
||||
}
|
||||
if err := syncpkg.LogChange(ctx, s.pool, syncpkg.EntityPlaylist,
|
||||
syncpkg.FormatUUID(deleted.ID), syncpkg.OpDelete); err != nil {
|
||||
s.logger.Warn("playlists: LogChange delete failed", "playlist_id", deleted.ID, "err", err)
|
||||
}
|
||||
s.publish("playlist.deleted", callerID, playlistID)
|
||||
if deleted.CoverPath != nil && *deleted.CoverPath != "" {
|
||||
full := filepath.Join(s.dataDir, *deleted.CoverPath)
|
||||
@@ -415,20 +403,9 @@ func (s *Service) AppendTracks(ctx context.Context, callerID, playlistID pgtype.
|
||||
// exists.
|
||||
func (s *Service) ReplaceTracks(ctx context.Context, callerID, playlistID pgtype.UUID, trackIDs []pgtype.UUID) error {
|
||||
return s.changeTracks(ctx, callerID, playlistID, func(tx pgx.Tx) error {
|
||||
rows, err := tx.Query(ctx,
|
||||
`DELETE FROM playlist_tracks WHERE playlist_id = $1 RETURNING track_id`, playlistID)
|
||||
if err != nil {
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM playlist_tracks WHERE playlist_id = $1`, playlistID); err != nil {
|
||||
return fmt.Errorf("clear tracks: %w", err)
|
||||
}
|
||||
removed, err := pgx.CollectRows(rows, pgx.RowTo[pgtype.UUID])
|
||||
if err != nil {
|
||||
return fmt.Errorf("clear tracks: %w", err)
|
||||
}
|
||||
for _, tid := range removed {
|
||||
if err := logTrackChange(ctx, tx, playlistID, tid, syncpkg.OpDelete); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return appendTracks(ctx, tx, playlistID, trackIDs)
|
||||
})
|
||||
}
|
||||
@@ -464,7 +441,8 @@ func (s *Service) removePositions(ctx context.Context, callerID, playlistID pgty
|
||||
return s.changeTracks(ctx, callerID, playlistID, func(tx pgx.Tx) error {
|
||||
tq := dbq.New(tx)
|
||||
for _, position := range order {
|
||||
// The track id names the change for clients that sync.
|
||||
// Read first: a missing position is ErrNotFound, and expect
|
||||
// is checked against the row's track.
|
||||
var deletedTrackID pgtype.UUID
|
||||
if err := tx.QueryRow(ctx,
|
||||
`SELECT track_id FROM playlist_tracks WHERE playlist_id = $1 AND position = $2`,
|
||||
@@ -484,9 +462,6 @@ func (s *Service) removePositions(ctx context.Context, callerID, playlistID pgty
|
||||
}); err != nil {
|
||||
return fmt.Errorf("delete track row: %w", err)
|
||||
}
|
||||
if err := logTrackChange(ctx, tx, playlistID, deletedTrackID, syncpkg.OpDelete); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tq.RenumberPlaylistTracksAfter(ctx, dbq.RenumberPlaylistTracksAfterParams{
|
||||
PlaylistID: playlistID,
|
||||
Position: position,
|
||||
@@ -543,20 +518,6 @@ func appendTracks(ctx context.Context, tx pgx.Tx, playlistID pgtype.UUID, trackI
|
||||
}
|
||||
return fmt.Errorf("append track: %w", err)
|
||||
}
|
||||
if err := logTrackChange(ctx, tx, playlistID, tid, syncpkg.OpUpsert); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// logTrackChange records a playlist entry's change for clients that sync,
|
||||
// in the transaction that makes it.
|
||||
func logTrackChange(ctx context.Context, tx pgx.Tx, playlistID, trackID pgtype.UUID, op syncpkg.Op) error {
|
||||
if err := syncpkg.LogChange(ctx, tx, syncpkg.EntityPlaylistTrack,
|
||||
syncpkg.EncodePlaylistTrackID(syncpkg.FormatUUID(playlistID), syncpkg.FormatUUID(trackID)),
|
||||
op); err != nil {
|
||||
return fmt.Errorf("log change: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user