DUP-GO-7: queryWithDir and queryNoDir are near-identical SQL queries #41
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#41
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
In
internal/db/sessions.go(lines 442–520),queryWithDirandqueryNoDirare two 38-line SQL strings that differ only in oneWHEREclause condition and the argument list.Duplicated code
The entire
SELECTbody — theagentcoalesce, themodelthree-way CASE, theJOIN message, theWHERE json_extract, theORDER BY, andLIMIT 1— is copy-pasted verbatim between the two queries (76 lines total).Note
The author commented that two queries were chosen for "query plan reviewability" — a conscious trade-off.
Fix
Unify into a single dynamically-built query using the same
directoryWherepattern used elsewhere instats.go.Effort
Medium — deliberate choice, needs discussion before changing.