S2: Duplicated SQL CASE/WHERE construction in signals route #7
Reference in New Issue
Block a user
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?
Code Smell
File:
web/app/api/signals/route.tsBoth the delta branch and the value branch independently build the same SQL patterns:
seriesConditionsmap with parameterized combinator/item_key pairsfullWherecombining original WHERE with series conditions via ORorderCasefor ORDER BY CASE preserving sort orderThese ~16-18 lines are copy-pasted between the two branches (~35 lines total duplication). The inline parameter offset calculation (
param.current + idx * 2) is fragile and must be kept in sync.Why it matters
Any change to the series query pattern must be applied in two places. Easy to miss during refactoring.
Suggestion
Extract a helper function: