Aggregate only album keys that can survive the active filter while keeping full-album counts and sort dates. Preserve the established album page results across source, FTS, shadow, sort and cursor combinations.
With the supporting artist indexes, the 15,000-row host aggregate measured 6.190 ms before and 0.456 ms after. Pin the changed SQL shape and retain the old row-result digests.
Every Library read over scanned songs checked, row by row, whether a
download holds the same file: each of the row's path keys (about 40 per
song on Android) was probed against History. That check was most of the
cost of the tab counts, the album and artist pages, the Folders index,
search, the Home mix pages and the Autoplay sample, and the album
completeness filters also scanned the whole Library once per download.
LibraryDatabase now keeps the matching pairs of Library and History rows
in a connection-local TEMP table. It is rebuilt only after PRAGMA
data_version of either database (a commit by another connection) or
total_changes() (a write on this one) has moved, with DDL only, so the
rebuild itself writes no rows. Each read checks the stamp again after
its query and repeats the query with the per-row check if anything was
written in between, so results equal today's SQL. Without a stamp the
per-row check stays in use; the default SQL is unchanged.
Android key profile, 15,000 scanned songs and 5,000 downloads (host
SQLite 3.54): tab counts 302 -> 13 ms, album page 309 -> 22 ms, artist
page 250 -> 15 ms, Folders 869 -> 65 ms, Home mix pages 2.7 s -> 0.19 s,
Autoplay sample 2.2 s -> 0.40 s, Incomplete albums over 60 s -> 0.33 s.
A rebuild costs about 0.44 s there (0.02 s on the desktop profile) and
runs once per write.
Eight one-line re-export files remained from an earlier move into controllers, models and providers. Every import now points at the real file, so the shims are deleted.
Records the SQL and bound arguments of every track, album, count and artist
query across sort modes, filters and page shapes, so refactors of the queue
store cannot silently change Library ordering or filtering.