Batch playlist membership and resolution updates in one state transaction #45

Closed
opened 2026-09-05 22:42:16 +00:00 by tophattedcat · 0 comments
Owner

Problem

Sync commits membership replacement and then calls set_resolution_state separately for every track occurrence. Each call starts its own transaction and changes updated_at, including duplicate occurrences and unchanged resolution values.

This causes unnecessary commits and leaves a playlist's state memberships and resolutions partially updated after a later failure within the same plugin database. Cross-store partial completion is expected by the spec; this additional fragmentation within one store is avoidable.

Proposed change

Provide a focused state-store operation that saves one playlist's memberships and unique-track resolution decisions together. Avoid redundant resolution updates while preserving Apple descriptor refresh and permanent skips.

Acceptance criteria

  • A failure while saving resolutions rolls back that playlist's plugin-state membership/resolution changes together.
  • Duplicate occurrences remain in memberships but do not trigger separate resolution commits.
  • Historical tracks and permanent skips are preserved.
  • Repeating the same desired sync remains idempotent.
  • Independent-store recovery and pruning semantics remain consistent with SPEC.md section 11.
  • Add focused transaction rollback and duplicate-occurrence tests.

References: beetsplug/appleplaylists/sync.py:177-191, state.py:127-161, state.py:228-255. Audit finding 4 (medium).

## Problem Sync commits membership replacement and then calls `set_resolution_state` separately for every track occurrence. Each call starts its own transaction and changes updated_at, including duplicate occurrences and unchanged resolution values. This causes unnecessary commits and leaves a playlist's state memberships and resolutions partially updated after a later failure within the same plugin database. Cross-store partial completion is expected by the spec; this additional fragmentation within one store is avoidable. ## Proposed change Provide a focused state-store operation that saves one playlist's memberships and unique-track resolution decisions together. Avoid redundant resolution updates while preserving Apple descriptor refresh and permanent skips. ## Acceptance criteria - A failure while saving resolutions rolls back that playlist's plugin-state membership/resolution changes together. - Duplicate occurrences remain in memberships but do not trigger separate resolution commits. - Historical tracks and permanent skips are preserved. - Repeating the same desired sync remains idempotent. - Independent-store recovery and pruning semantics remain consistent with SPEC.md section 11. - Add focused transaction rollback and duplicate-occurrence tests. References: `beetsplug/appleplaylists/sync.py:177-191`, `state.py:127-161`, `state.py:228-255`. Audit finding 4 (medium).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
coop/beets-appleplaylists#45
No description provided.