Files
music_library/backlog/archive/tasks/ml-1 - Add-default-limit-to-Maintenance-orphan-queries.md
T
2026-05-04 21:22:27 +01:00

2.3 KiB

id, title, status, assignee, created_date, updated_date, labels, dependencies, references, priority
id title status assignee created_date updated_date labels dependencies references priority
ML-1 Add default :limit to Maintenance orphan queries To Do
2026-04-20 08:44 2026-04-24 06:59
https://github.com/cloud8421/music_library/issues/183
low

Description

GitHub: created 2026-04-16 · updated 2026-04-16

Summary

Two Maintenance queries are unbounded when called without the :limit option. Currently invoked only from a Mix task, so not user-facing, but defensively adding a default prevents accidental full-table scans on future call sites.

Evidence

  • lib/music_library/maintenance.ex:77get_artists_missing_musicbrainz_id/1
  • lib/music_library/maintenance.ex:108get_albums_missing_musicbrainz_id/1

Both accept an opts keyword list with :limit, but neither applies a default. Callers in lib/mix/tasks/scrobble/audit.ex pass explicit limits, so today is fine.

Fix

Apply a sensible default (e.g. 1000) to the :limit option if not provided:

def get_artists_missing_musicbrainz_id(opts \\ []) do
  limit = Keyword.get(opts, :limit, 1000)
  # ...
end

Acceptance Criteria

  • #1 Both functions apply a default limit when none is supplied
  • #2 Existing callers continue to override when they need a different value

Final Summary

Closed as not-planned (YAGNI).

The proposed fix was to add a default :limit (e.g. 1000) to get_artists_missing_musicbrainz_id/1 and get_albums_missing_musicbrainz_id/1 in lib/music_library/maintenance.ex to defend against future unbounded call sites.

Assessment: the dataset ceiling is <5,000 records and <1,000 artists for the next 2-3 years. An unbounded scan of the tracks table grouped by artist/album JSON fields is well within acceptable cost for this size. Adding a default limit would silently cap results on a dataset that should never need capping, and the only current callers (lib/mix/tasks/scrobble/audit.ex:127,149) already invoke without :limit on purpose.

A follow-up could remove the :limit option entirely to simplify the API — not tracked here; revisit if the option starts causing confusion.