DUP-GO-6: pagination offset/limit block duplicated in populateSessionLog and populateProjectLog #47

Closed
opened 2026-05-27 16:57:28 +02:00 by dries · 0 comments
Owner

Summary

populateSessionLog (lines 591–699) and populateProjectLog (lines 704–807) in internal/db/stats.go both end with an identical 7-line pagination block:

if offset < 0 { offset = 0 }
if offset > len(entries) { offset = len(entries) }
paged := entries[offset:]
if limit > 0 && len(paged) > limit { paged = paged[:limit] }

There is also a near-identical cost-descending sort with tie-breaking by LastRequestTime at lines 675–681 and 784–790.

Fix

Extract paginateSlice[T](entries []T, offset, limit int) []T using Go generics. Extract the sort into a shared comparator.

Effort

Trivial.

## Summary `populateSessionLog` (lines 591–699) and `populateProjectLog` (lines 704–807) in `internal/db/stats.go` both end with an identical 7-line pagination block: ```go if offset < 0 { offset = 0 } if offset > len(entries) { offset = len(entries) } paged := entries[offset:] if limit > 0 && len(paged) > limit { paged = paged[:limit] } ``` There is also a near-identical cost-descending sort with tie-breaking by `LastRequestTime` at lines 675–681 and 784–790. ## Fix Extract `paginateSlice[T](entries []T, offset, limit int) []T` using Go generics. Extract the sort into a shared comparator. ## Effort Trivial.
dries closed this issue 2026-07-04 19:53:55 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#47
No description provided.