refactor: split internal/db/stats.go (1318 lines, 15 query methods) #22

Closed
opened 2026-05-17 17:16:25 +02:00 by dries · 0 comments
Owner

Problem

internal/db/stats.go is 1318 lines and contains 15 distinct DB query methods covering completely separate concerns:

  • GetStats — top-line counts
  • GetMetricsDashboard + 5 private aggregators (scanDashboardRows, aggregateSummaryAndBuckets, populateSessionLog, populateProjectLog, lookupSessionMetadata)
  • GetProjects
  • GetDailyActivity
  • GetModelUsage
  • GetRecentModels
  • GetHourlyTokensByModel
  • GetHourlyActivity
  • GetNewAssistantMessages / GetMaxMessageTime (LLM metrics loop)

This is also the largest community in the GitNexus graph (102 symbols, cohesion 0.98) — a sign that this file has become a catch-all.

Suggested split

New file Methods
db/metrics_dashboard.go GetMetricsDashboard, scanDashboardRows, aggregateSummaryAndBuckets, populateSessionLog, populateProjectLog, lookupSessionMetadata, related types
db/activity.go GetDailyActivity, GetHourlyActivity, GetHourlyTokensByModel, GetNewAssistantMessages, GetMaxMessageTime
db/projects.go GetProjects, GetModelUsage, GetRecentModels
db/stats.go GetStats, directoryWhere, extractModelProvider, shared helpers

This is a pure file-level refactor — no behaviour change, no API change.

References

  • internal/db/stats.go:1
  • GitNexus Community "Db": 102 symbols, highest symbol count in the project
## Problem `internal/db/stats.go` is 1318 lines and contains 15 distinct DB query methods covering completely separate concerns: - `GetStats` — top-line counts - `GetMetricsDashboard` + 5 private aggregators (`scanDashboardRows`, `aggregateSummaryAndBuckets`, `populateSessionLog`, `populateProjectLog`, `lookupSessionMetadata`) - `GetProjects` - `GetDailyActivity` - `GetModelUsage` - `GetRecentModels` - `GetHourlyTokensByModel` - `GetHourlyActivity` - `GetNewAssistantMessages` / `GetMaxMessageTime` (LLM metrics loop) This is also the largest community in the GitNexus graph (102 symbols, cohesion 0.98) — a sign that this file has become a catch-all. ## Suggested split | New file | Methods | |---|---| | `db/metrics_dashboard.go` | `GetMetricsDashboard`, `scanDashboardRows`, `aggregateSummaryAndBuckets`, `populateSessionLog`, `populateProjectLog`, `lookupSessionMetadata`, related types | | `db/activity.go` | `GetDailyActivity`, `GetHourlyActivity`, `GetHourlyTokensByModel`, `GetNewAssistantMessages`, `GetMaxMessageTime` | | `db/projects.go` | `GetProjects`, `GetModelUsage`, `GetRecentModels` | | `db/stats.go` | `GetStats`, `directoryWhere`, `extractModelProvider`, shared helpers | This is a pure file-level refactor — no behaviour change, no API change. ## References - `internal/db/stats.go:1` - GitNexus Community "Db": 102 symbols, highest symbol count in the project
dries closed this issue 2026-07-08 21:15:33 +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#22
No description provided.