corpus

Log | Files | Refs | README | LICENSE

commit 99e802804943177b0110926601096350e82903a3
parent 1311482ca3499dfa4106f988d04b0f3cf86261b4
Author: mtmn <miro@haravara.org>
Date:   Sat, 18 Apr 2026 23:37:14 +0200

fix: initialSync halts syncing, broken range query

Diffstat:
Msrc/Client.elm | 2+-
Msrc/Db.purs | 4++--
Msrc/Main.purs | 14++++++++++----
Musers.dhall | 1+
Musers.json | 26+++++++++++++-------------
5 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/Client.elm b/src/Client.elm @@ -873,7 +873,7 @@ renderStatSection expandedSections loadedSections mField title entries = div [ class "stats-section" ] [ h2 [] [ text title ] , if List.isEmpty entries then - div [ class "stats-empty" ] [ text "no data yet" ] + div [ class "stats-empty" ] [ text "beyond here lies nothing" ] else ul [] (List.map (renderStatEntry maxCount mField) visible) diff --git a/src/Db.purs b/src/Db.purs @@ -262,8 +262,8 @@ getStats conn mPeriod mFrom mTo mSection = do buildTimeFilterAndParams :: { timeFilter :: String, params :: Array Foreign } buildTimeFilterAndParams = case mFrom, mTo of Just from, Just to -> - { timeFilter: " AND s.listened_at >= CAST(epoch(TIMESTAMP ?) AS INTEGER) AND s.listened_at < CAST(epoch(TIMESTAMP ?) AS INTEGER) + 86400" - , params: [ unsafeCoerce (from <> "T00:00:00"), unsafeCoerce (to <> "T00:00:00") ] + { timeFilter: " AND s.listened_at >= CAST(epoch(TIMESTAMP '" <> from <> " 00:00:00') AS INTEGER) AND s.listened_at < CAST(epoch(TIMESTAMP '" <> to <> " 00:00:00') AS INTEGER) + 86400" + , params: [] } _, _ -> case mPeriod >>= fromString of Just days -> diff --git a/src/Main.purs b/src/Main.purs @@ -182,13 +182,16 @@ lbSyncOnce conn username slug writeLock initialSyncEnabled = void performFullSyn $ Log.info $ "ListenBrainz batch: added " <> show added <> ", " <> show hitCount <> " already present." let allExist = hitCount == length listens && not (null listens) - if allExist || null listens || not initialSyncEnabled then do + if allExist || null listens then do when (added > 0) $ Log.info $ "ListenBrainz sync complete. Added " <> show added <> " new scrobbles." recordSuccess added - else do + else if initialSyncEnabled then do total <- paginateUntilDone 2 minTs added Log.info $ "ListenBrainz sync complete. Added " <> show total <> " new scrobbles." recordSuccess total + else do + when (added > 0) $ Log.info $ "ListenBrainz sync complete. Added " <> show added <> " new scrobbles." + recordSuccess added Left err -> do Log.error $ "Sync fetch error: " <> Exception.message err liftEffect $ Metrics.incSyncRuns slug "listenbrainz" "error" @@ -256,13 +259,16 @@ lfSyncOnce conn apiKey lfmUser slug writeLock initialSyncEnabled = do let validTracks = mapMaybe lastfmTrackToListen tracks allExist = hitCount == length validTracks && not (null validTracks) - if allExist || totalPages <= 1 || not initialSyncEnabled then do + if allExist || totalPages <= 1 then do when (added > 0) $ Log.info $ "Last.fm sync complete. Added " <> show added <> " new scrobbles." recordSuccess added - else do + else if initialSyncEnabled then do total <- paginateLastfmUntilDone 2 totalPages Nothing added Log.info $ "Last.fm sync complete. Added " <> show total <> " new scrobbles." recordSuccess total + else do + when (added > 0) $ Log.info $ "Last.fm sync complete. Added " <> show added <> " new scrobbles." + recordSuccess added paginateLastfmUntilDone page totalPages mTo acc | page > totalPages = pure acc diff --git a/users.dhall b/users.dhall @@ -26,6 +26,7 @@ in { users = with listenbrainzUser = Some "mtmn" with databaseFile = "corpus-mtmn.db" with backupEnabled = True + with initialSync = True } ] } diff --git a/users.json b/users.json @@ -1,15 +1,15 @@ { - "users": [ - { - "config": { - "backupEnabled": true, - "backupIntervalHours": 1, - "coverCacheEnabled": true, - "databaseFile": "corpus-mtmn.db", - "initialSync": false, - "listenbrainzUser": "mtmn" - }, - "slug": "" - } - ] + "users": [ + { + "config": { + "backupEnabled": true, + "backupIntervalHours": 1, + "coverCacheEnabled": true, + "databaseFile": "corpus-mtmn.db", + "initialSync": true, + "listenbrainzUser": "mtmn" + }, + "slug": "" + } + ] }