Commit Graph

1955 Commits

Author SHA1 Message Date
Claudio Ortolina 9370e5f64d No need to use a case 2026-04-12 22:05:09 +01:00
Claudio Ortolina 02761428c1 Format map and list query params as JSON 2026-04-11 23:57:40 +01:00
Claudio Ortolina d8c84e787b Optimize ListeningStats query performance
Three independent refactors of lib/music_library/listening_stats.ex,
measured against the dev DB (104k tracks) via bench/listening_stats.exs:

| Query                           | Baseline  | After     | Speedup |
|---------------------------------|-----------|-----------|---------|
| recent_activity(tz, 100)        | 38.98 ms  | 2.87 ms   | 13.6x   |
| list_tracks(page 1, 200)        | 47.30 ms  | 4.81 ms   | 9.8x    |
| get_top_artists_by_days(7)      | 66.51 ms  | 1.02 ms   | 65x     |
| get_top_artists_by_days(30)     | 67.41 ms  | 2.84 ms   | 23.7x   |
| get_top_artists_by_days(365)    | 76.03 ms  | 25.57 ms  | 3.0x    |
| get_top_albums_by_days(7)       | 92.63 ms  | 1.61 ms   | 57.5x   |
| get_top_albums_by_days(30)      | 94.52 ms  | 3.69 ms   | 25.6x   |
| get_top_albums_by_days(365)     | 105.23 ms | 32.81 ms  | 3.2x    |
| get_top_artists(limit: 10)      | 123.96 ms | 101.68 ms | 1.22x   |
| get_top_albums(limit: 10)       | 209.64 ms | 108.23 ms | 1.94x   |

tracks_with_record_info_query/0 now uses correlated scalar subqueries
against record_releases and artist_records instead of materializing
helper subqueries on every call. The cost scales with the outer LIMIT,
not with the size of record_releases.

top_albums_base_query/0 and top_artists_base_query/0 are replaced by
aggregate_query + attach_metadata pairs. The pattern is aggregate first,
attach metadata second: GROUP BY runs against the raw track scan, then
a tiny outer SELECT attaches record_releases / artist_infos lookups for
the <= 10 result rows via correlated subqueries.

tracks_since_query/1 wraps the date-filtered inner scan with limit: -1.
SQLite cannot flatten a subquery that has a LIMIT, so it materializes
the date-bounded subset and the optimizer uses the timestamp index for
the range scan instead of the album/artist composite index. This trick
replaces SQLite's WITH ... AS MATERIALIZED (which ecto_sqlite3 doesn't
expose).

All json_extract(?, '\$.path') fragments use the canonical form rather
than the equivalent ? ->> '\$.path' shorthand. SQLite's index matcher
requires the GROUP BY expression to match the index expression
textually to use the composite index for natural ordering.

collected_releases_query/0 and wishlisted_releases_query/0 are removed
from Collection and Wishlist — they had a single internal caller that
no longer exists after the refactor.

New regression tests lock the semantics that the optimized queries
must preserve:
- count(DISTINCT scrobbled_at_uts) — 579 duplicate timestamps exist in
  the dev DB from rapid Last.fm scrobbles, so replacing with count(*)
  would silently change results
- :artist_id key in list_tracks result maps — ScrobbledTracksLive.Index
  destructures it even though the template body never references it

Closes #148
2026-04-11 23:36:32 +01:00
Claudio Ortolina 3da0865725 Drop Records embedding wrappers 2026-04-11 21:43:00 +01:00
Claudio Ortolina a608be7387 Move regenerate_artist_embeddings into Similarity 2026-04-11 21:43:00 +01:00
Claudio Ortolina 789ce04b87 Use MusicBrainz.get_all_releases in Records 2026-04-11 21:40:32 +01:00
Claudio Ortolina b7af9557c1 Add MusicBrainz.get_all_releases/1 2026-04-11 21:40:32 +01:00
Claudio Ortolina 8826834549 Fix release status badge in grouped records on this day
The tooltip was using the group representative instead of the
actual record, causing all items in a group to show the same
badge regardless of their own selected_release_id.
2026-04-10 10:38:48 +01:00
Claudio Ortolina 1c720c8394 Add query timing metadata to reporter output 2026-04-10 10:30:05 +01:00
Claudio Ortolina 27148c6507 Add dev query reporter and skill
Ecto telemetry reporter that captures executed SQL queries
to a log file with interpolated parameters and source
locations. Activated/deactivated at runtime via Tidewave
for LLM-driven query analysis workflows.
2026-04-10 10:27:12 +01:00
Claudio Ortolina 59937dadb8 Remove duplication around searching scrobbled tracks
Fixes #157
2026-04-09 06:57:24 +01:00
Claudio Ortolina 49d26e1fd0 Switch the release component to a form to enable recovery 2026-04-08 18:22:44 +01:00
Claudio Ortolina d406e98fce Use message index for chat DOM ids 2026-04-08 12:42:01 +01:00
Claudio Ortolina d691b1b432 Fix encoding of past messages in LLM request 2026-04-08 12:34:45 +01:00
Claudio Ortolina 91931e649c Remove experimental comment (approach works)
Closes #162
2026-04-08 06:52:31 +01:00
Claudio Ortolina edc4e51d1d Optimize record set compaction
Closes #154
2026-04-06 18:38:56 +01:00
Claudio Ortolina 2609adbf84 Address Lumis api deprecation 2026-04-06 10:27:13 +01:00
Claudio Ortolina 7b5b7e68dd Harden OpenAI api layer
- Support rate limiting
- Add proper error handling (don't rely on exceptions)

Closes #147
2026-04-05 16:01:29 +01:00
Claudio Ortolina a5df68c7ad Don't suppress errors when fetching artist Last.fm data
Closes #149
2026-04-05 15:47:36 +01:00
Claudio Ortolina 501ff18733 Can copy a chat message 2026-04-05 14:35:03 +01:00
Claudio Ortolina 40ea3aaa2a Add fallback error images for scrobble activity 2026-04-05 08:35:23 +01:00
Claudio Ortolina 4be9db6417 Refactor DefaultPrompt into Chats.Prompt with build/2 2026-04-05 08:32:03 +01:00
Claudio Ortolina f9155f8c52 Try and control the chat responses style 2026-04-04 23:35:46 +01:00
Claudio Ortolina ec12be613b Extract a default prompt 2026-04-04 23:35:30 +01:00
Claudio Ortolina 86fd3134f1 Reduce repetitive LLM chat responses (#146)
Replace "always provide a link" with conditional linking and add
instructions to vary response style and avoid restating information
already covered in the conversation.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-04 18:32:57 +01:00
Claudio Ortolina b9be62a500 Async barcode scan batch import for 2+ new records
When barcode scan results contain at least 2 new records,
enqueue individual Oban jobs instead of importing synchronously.
Wishlisted/collected/not_found results still process synchronously.
2026-04-04 10:20:50 +01:00
Claudio Ortolina 2f9460d2cb Regenerate embeddings only when the test representation changes 2026-04-04 08:32:29 +01:00
Claudio Ortolina cd52890f86 Move release status badge inside group 2026-04-03 17:48:13 +01:00
Claudio Ortolina 4bfe27e6c8 Cancel refresh cover job if image is not available 2026-04-03 12:43:50 +01:00
Claudio Ortolina 9d0170dad3 Hide universal search shortcuts on mobile 2026-04-02 17:15:31 +01:00
Claudio Ortolina 555e7065dc Fix display of metadata in universal search results 2026-04-02 17:15:04 +01:00
Claudio Ortolina 90538e7890 Move status tooltip badge 2026-04-02 16:22:57 +01:00
Claudio Ortolina a390a992cc Remove tooltip (fails for unknown reasons) 2026-04-02 13:21:51 +01:00
Claudio Ortolina 98c2f85258 Use a tooltip for release status 2026-04-02 11:57:41 +01:00
Claudio Ortolina 3f7da55e50 Add a release tracked badge to records in lists 2026-04-02 11:52:07 +01:00
Claudio Ortolina 5be889ba58 Remove rounding from selected release in release list 2026-04-01 21:42:08 +01:00
Claudio Ortolina 4e8f1fd6f0 Fix cover image distortion in scrobble activity 2026-04-01 21:14:18 +01:00
Claudio Ortolina b5e934e36f Remove unnecessary padding (fixes text overflow) 2026-04-01 11:13:23 +01:00
Claudio Ortolina 9bdefa9f6d Fix stats section title sizes on iPad mini 2026-04-01 11:08:29 +01:00
Claudio Ortolina 7f406ce455 Replace deprecated {:discard, _} with {:cancel, _} 2026-04-01 09:38:05 +01:00
Claudio Ortolina 553ad2bbb9 Discard worker when no wikipedia entry is present 2026-04-01 08:52:28 +01:00
Claudio Ortolina e3a6c0563b Do not invert order of artist sections on mobile 2026-04-01 07:51:29 +01:00
Claudio Ortolina 6fcca38e27 Make sure to pull artists info when record is updated
Catches the scenario when a new artist is added
2026-04-01 07:11:47 +01:00
Claudio Ortolina 7d65a7d4ab Make sure create record returns updated record 2026-04-01 07:06:33 +01:00
Claudio Ortolina e0a277e215 Always open chat links in new tabs 2026-03-31 19:17:58 +01:00
Claudio Ortolina c913dab692 Return controlled errors from genre population
Closes #142
2026-03-30 15:01:42 +01:00
Claudio Ortolina 92a36b915a Harden public asset endpoint against invalid payloads
Closes #143
2026-03-30 14:56:40 +01:00
Claudio Ortolina 45fd414f1b Use friendly error messages in Last.fm callback
Closes #145
2026-03-30 14:42:20 +01:00
Claudio Ortolina b0018db89d Improve error handling for color extraction
Includes a around embedding generation, which was happening twice (the
first call was redundant as record embeddings are always regenerated
after their parent artist embeddings are regenerated).

Closes #144.
2026-03-30 14:29:44 +01:00
Claudio Ortolina 53178b373b Add barcode scan quick action 2026-03-30 13:26:04 +01:00