Remove repeated membership queries and full-library scans from local workflows #48

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

Problem

managed_track_rows first fetches track IDs and then runs two additional queries for each track. The per-track membership query is not supported by an index beginning with apple_library_track_id.

Interactive match scans the entire beets library for every managed Apple track, including tracks that will immediately be skipped because they are already resolved. Explicit replacement/displacement handling performs additional scans.

Proposed change

Fetch managed tracks and memberships with a joined/batched query and group the rows. Build a live association index once for interactive matching and update it after decisions. Add an index only if the resulting query plan needs it; any schema change must use a numbered forward-only migration.

Acceptance criteria

  • Reporting query count does not grow by two queries per track.
  • Interactive processing does not rescan the complete library per Apple track.
  • Association indexing remains correct after replacements and displacement.
  • Reporting order, distinct playlist names, historical filtering, and interactive resume behavior are preserved.
  • Verify using meaningful query/iteration-count tests or a representative isolated benchmark.

References: beetsplug/appleplaylists/state.py:178-211, __init__.py:412-435, __init__.py:479-485. Audit finding 7 (medium).

## Problem managed_track_rows first fetches track IDs and then runs two additional queries for each track. The per-track membership query is not supported by an index beginning with apple_library_track_id. Interactive match scans the entire beets library for every managed Apple track, including tracks that will immediately be skipped because they are already resolved. Explicit replacement/displacement handling performs additional scans. ## Proposed change Fetch managed tracks and memberships with a joined/batched query and group the rows. Build a live association index once for interactive matching and update it after decisions. Add an index only if the resulting query plan needs it; any schema change must use a numbered forward-only migration. ## Acceptance criteria - Reporting query count does not grow by two queries per track. - Interactive processing does not rescan the complete library per Apple track. - Association indexing remains correct after replacements and displacement. - Reporting order, distinct playlist names, historical filtering, and interactive resume behavior are preserved. - Verify using meaningful query/iteration-count tests or a representative isolated benchmark. References: `beetsplug/appleplaylists/state.py:178-211`, `__init__.py:412-435`, `__init__.py:479-485`. Audit finding 7 (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#48
No description provided.