Skip to content

Commit 217714d

Browse files
Job-detail log retention depended on the active display sort instead of the stored log order. After switching to oldest-first, the next refresh could discard newly fetched lines while still advancing the last-seen timestamp.
Keep the in-memory log buffer in ascending timestamp order and always trim from the oldest side. Sorting now affects rendering only, so refreshes and backfills retain the newest log entries regardless of the selected view.
1 parent f38a358 commit 217714d

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

dashboard/src/Dashboard/Component/JobDetail.purs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ handleAction = case _ of
490490
let newLogs = Array.filter (isNewerThan state.lastLogTimestamp) info.logs
491491
when (not (Array.null newLogs)) do
492492
let lastTs = map _.timestamp (Array.last newLogs)
493-
-- Logs are always stored in ASC order; new logs are appended at the end.
494-
let combined = capLogs state.logSortOrder (state.allLogs <> newLogs)
493+
let combined = keepNewestLogs (state.allLogs <> newLogs)
495494
H.modify_ _ { allLogs = combined, lastLogTimestamp = lastTs }
496495
-- Update job status and logUntil from the refreshed data
497496
H.modify_ _ { job = Just job, logUntil = info.finishedAt, currentTime = Just now }
@@ -536,14 +535,11 @@ logPageSize = 200
536535
logTotalPages :: Int -> Int
537536
logTotalPages total = max 1 (((total - 1) / logPageSize) + 1)
538537

539-
-- | Cap an array of logs (stored in ASC order) to `maxLogEntries`, trimming
540-
-- | from the end furthest from the user's current view.
541-
capLogs :: SortOrder -> Array LogLine -> Array LogLine
542-
capLogs sortOrder logs =
538+
-- | Cap an array of logs stored in ASC order by keeping the newest entries.
539+
keepNewestLogs :: Array LogLine -> Array LogLine
540+
keepNewestLogs logs =
543541
if Array.length logs <= maxLogEntries then logs
544-
else case sortOrder of
545-
ASC -> Array.take maxLogEntries logs
546-
DESC -> Array.drop (Array.length logs - maxLogEntries) logs
542+
else Array.drop (Array.length logs - maxLogEntries) logs
547543

548544
-- | Maximum number of pagination requests when fetching all remaining logs.
549545
maxPaginationIterations :: Int
@@ -611,7 +607,7 @@ fetchAllRemainingLogs = go 0
611607
pure unit
612608
else do
613609
currentState <- H.get
614-
let combined = capLogs currentState.logSortOrder (currentState.allLogs <> newLogs)
610+
let combined = keepNewestLogs (currentState.allLogs <> newLogs)
615611
let lastTs = map _.timestamp (Array.last combined)
616612
H.modify_ _ { allLogs = combined, lastLogTimestamp = lastTs }
617613
go (iteration + 1)

0 commit comments

Comments
 (0)