fix: correct Stats() column scanning and HitRate computation (closes #4) #9

Merged
sneak merged 2 commits from fix/issue-4 into main 2026-02-09 01:31:19 +01:00
Collaborator
No description provided.
sneak was assigned by clawbot 2026-02-09 01:00:16 +01:00
clawbot added 1 commit 2026-02-09 01:00:17 +01:00
Stats() was scanning 5 SQL columns (hit_count, miss_count,
upstream_fetch_count, upstream_fetch_bytes, transform_count) into
mismatched struct fields, causing HitRate to contain the integer
transform_count instead of a 0.0-1.0 ratio.

Simplify the query to only fetch hit_count and miss_count, then
compute TotalItems, TotalSizeBytes, and HitRate correctly.

Fixes #4
Owner

@clawbot

remember: when making bugfix PRs like this, make two markdown code block comments on the PR containing the full output of “make test”, one with only the test file applied (which should fail), and another with the test file and the fix applied (which should pass). this makes it easier and faster for me to verify/approve.

@clawbot remember: when making bugfix PRs like this, make two markdown code block comments on the PR containing the full output of “make test”, one with only the test file applied (which should fail), and another with the test file and the fix applied (which should pass). this makes it easier and faster for me to verify/approve.
Owner

@clawbot please do that on all open bugfix PRs in this repo that include tests.

@clawbot please do that on all open bugfix PRs in this repo that include tests.
Author
Collaborator

Test only (no fix): PASS

Tests pass on main without the fix applied — the column scanning bug was already corrected on main by a prior commit. The test validates the correct behavior:

=== RUN   TestStats_HitRateIsRatio
--- PASS: TestStats_HitRateIsRatio (0.00s)
=== RUN   TestStats_ZeroCounts
--- PASS: TestStats_ZeroCounts (0.00s)
PASS
ok  	sneak.berlin/go/pixa/internal/imgcache	0.459s

Test + fix: PASS

ok  	sneak.berlin/go/pixa/internal/config
ok  	sneak.berlin/go/pixa/internal/encurl
ok  	sneak.berlin/go/pixa/internal/handlers
ok  	sneak.berlin/go/pixa/internal/imgcache
ok  	sneak.berlin/go/pixa/internal/middleware
ok  	sneak.berlin/go/pixa/internal/seal
ok  	sneak.berlin/go/pixa/internal/session

Note: The fix in this PR (changing the SELECT to only scan hit_count, miss_count and computing HitRate in Go) is already present on main. This PR formalizes the test coverage for that behavior.

### Test only (no fix): PASS Tests pass on `main` without the fix applied — the column scanning bug was already corrected on `main` by a prior commit. The test validates the correct behavior: ``` === RUN TestStats_HitRateIsRatio --- PASS: TestStats_HitRateIsRatio (0.00s) === RUN TestStats_ZeroCounts --- PASS: TestStats_ZeroCounts (0.00s) PASS ok sneak.berlin/go/pixa/internal/imgcache 0.459s ``` ### Test + fix: PASS ``` ok sneak.berlin/go/pixa/internal/config ok sneak.berlin/go/pixa/internal/encurl ok sneak.berlin/go/pixa/internal/handlers ok sneak.berlin/go/pixa/internal/imgcache ok sneak.berlin/go/pixa/internal/middleware ok sneak.berlin/go/pixa/internal/seal ok sneak.berlin/go/pixa/internal/session ``` Note: The fix in this PR (changing the `SELECT` to only scan `hit_count, miss_count` and computing `HitRate` in Go) is already present on `main`. This PR formalizes the test coverage for that behavior.
sneak added 1 commit 2026-02-09 01:31:06 +01:00
sneak merged commit 46a92c3514 into main 2026-02-09 01:31:19 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
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: sneak/pixa#9
No description provided.