Koito/internal/db/psql
safierinx-a 8ce6ec494d Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter
Adopts ListenBrainz-inspired patterns to speed up imports from ~24h to
under 30 minutes for 49k scrobbles.

Phase 1 - track_lookup cache table:
- New migration (000006) adds persistent entity lookup cache
- Maps normalized (artist, track, album) → (artist_id, album_id, track_id)
- SubmitListen fast path: cache hit skips 18 DB queries → 2 queries
- Cache populated after entity resolution, invalidated on merge/delete
- Benefits both live scrobbles and imports

Phase 2 - SaveListensBatch:
- New batch listen insert using pgx CopyFrom → temp table → INSERT ON CONFLICT
- Thousands of inserts per second vs one-at-a-time

Phase 3 - BulkSubmitter:
- Reusable import accelerator for all importers
- Pre-deduplicates scrobbles by (artist, track, album) in memory
- Worker pool (4 goroutines) for parallel entity creation on cache miss
- Batch listen insertion via SaveListensBatch

Phase 4 - Migrate importers:
- Maloja, Spotify, LastFM, ListenBrainz importers use BulkSubmitter
- Koito importer left as-is (already fast with pre-resolved IDs)

Phase 5 - Skip image lookups during import:
- GetArtistImage/GetAlbumImage calls fully skipped when SkipCacheImage=true
- Background tasks (FetchMissingArtistImages/FetchMissingAlbumImages) backfill

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 04:17:50 +05:30
..
album.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
album_test.go fix: associate artists with merged items 2025-06-15 22:25:55 -04:00
artist.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
artist_test.go feat: v0.0.5 2025-06-15 19:09:44 -04:00
counts.go feat: Rewind (#116) 2025-12-31 18:44:55 -05:00
counts_test.go transition time ranged queries to timeframe (#117) 2026-01-01 01:56:16 -05:00
exports.go feat: v0.0.10 (#23) 2025-06-18 08:48:19 -04:00
images.go feat: refetch missing images on startup (#160) 2026-01-20 12:10:54 -05:00
images_test.go chore: initial public commit 2025-06-11 19:45:39 -04:00
interest.go fix: correct interest bucket queries (#169) 2026-01-22 17:01:46 -05:00
interest_test.go feat: interest over time graph (#127) 2026-01-12 16:20:31 -05:00
listen.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
listen_activity.go fix: get current time in tz for listen activity (#146) 2026-01-15 19:36:48 -05:00
listen_activity_test.go fix: get current time in tz for listen activity (#146) 2026-01-15 19:36:48 -05:00
listen_test.go transition time ranged queries to timeframe (#117) 2026-01-01 01:56:16 -05:00
merge.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
merge_test.go fix: release associations and add cleanup migration (#168) 2026-01-22 15:33:38 -05:00
psql.go Pre-release version v0.0.13 (#52) 2025-07-26 15:57:46 -04:00
psql_test.go feat: version v0.0.2 2025-06-14 19:14:30 -04:00
search.go feat: v0.0.8 2025-06-16 21:55:39 -04:00
search_test.go chore: weaken search similarity constraint 2025-06-13 18:35:59 -04:00
sessions.go feat: v0.0.8 2025-06-16 21:55:39 -04:00
sessions_test.go chore: initial public commit 2025-06-11 19:45:39 -04:00
top_albums.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
top_albums_test.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
top_artists.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
top_artists_test.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
top_tracks.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
top_tracks_test.go fix: use sql rank (#148) 2026-01-15 21:08:30 -05:00
track.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
track_lookup.go Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter 2026-03-25 04:17:50 +05:30
track_test.go fix: release associations and add cleanup migration (#168) 2026-01-22 15:33:38 -05:00
user.go Pre-release version v0.0.13 (#52) 2025-07-26 15:57:46 -04:00
user_test.go chore: initial public commit 2025-06-11 19:45:39 -04:00