mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 12:01:52 -07:00
Add bulk import optimization: track_lookup cache, batch inserts, BulkSubmitter
This commit is contained in:
parent
0ec7b458cc
commit
ae373a7090
21 changed files with 1296 additions and 125 deletions
|
|
@ -77,6 +77,21 @@ func SubmitListen(ctx context.Context, store db.DB, opts SubmitListenOpts) error
|
|||
// bandaid to ensure new activity does not have sub-second precision
|
||||
opts.Time = opts.Time.Truncate(time.Second)
|
||||
|
||||
// Fast path: check lookup cache for known entity combo
|
||||
if !opts.SkipSaveListen {
|
||||
key := TrackLookupKey(opts.Artist, opts.TrackTitle, opts.ReleaseTitle)
|
||||
cached, err := store.GetTrackLookup(ctx, key)
|
||||
if err == nil && cached != nil {
|
||||
l.Debug().Msg("Track lookup cache hit — skipping entity resolution")
|
||||
return store.SaveListen(ctx, db.SaveListenOpts{
|
||||
TrackID: cached.TrackID,
|
||||
Time: opts.Time,
|
||||
UserID: opts.UserID,
|
||||
Client: opts.Client,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
artists, err := AssociateArtists(
|
||||
ctx,
|
||||
store,
|
||||
|
|
@ -168,6 +183,16 @@ func SubmitListen(ctx context.Context, store db.DB, opts SubmitListenOpts) error
|
|||
}
|
||||
}
|
||||
|
||||
// Populate lookup cache for future fast-path hits
|
||||
if len(artists) > 0 {
|
||||
store.SaveTrackLookup(ctx, db.SaveTrackLookupOpts{
|
||||
Key: TrackLookupKey(opts.Artist, opts.TrackTitle, opts.ReleaseTitle),
|
||||
ArtistID: artists[0].ID,
|
||||
AlbumID: rg.ID,
|
||||
TrackID: track.ID,
|
||||
})
|
||||
}
|
||||
|
||||
if opts.IsNowPlaying {
|
||||
if track.Duration == 0 {
|
||||
memkv.Store.Set(strconv.Itoa(int(opts.UserID)), track.ID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue