Bug: Stats() scans database columns into wrong struct fields #4
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/pixa#4
Loading…
Reference in New Issue
Block a user
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?
Bug
In
internal/imgcache/cache.go, theStats()method scans SQL columns into mismatched struct fields:The scan maps:
upstream_fetch_count→TotalItems(wrong - this is fetch count, not item count)upstream_fetch_bytes→TotalSizeBytes(coincidentally reasonable but semantically wrong)transform_count→HitRate(completely wrong - scanning an INTEGER into a float64 field that should be a ratio)The subsequent queries then overwrite
TotalItemsandTotalSizeByteswith correct values, butHitRatefrom the first scan is an integer (transform_count) not a ratio.Then
HitRateis recalculated correctly only ifHitCount+MissCount > 0, but if they're both 0 (fresh DB),HitRateretains the garbage value from the transform_count scan.Impact
The
/metricsor any stats endpoint returns incorrect data. TheHitRatefield contains transform_count (an integer) instead of a 0.0-1.0 ratio.Fix
Scan into local variables matching the actual columns, or restructure the query to only fetch
hit_countandmiss_countfromcache_stats, then compute derived stats separately.