Repository navigation
feat(analytics): switch reporter to *database.Client + Ent - #1217
Merged
Merged
Conversation
This was referenced May 21, 2026
This was referenced May 21, 2026
Owner
Author
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 21:04
1742471 to
7883536
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 21:04
727302e to
dd54658
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 21:17
7883536 to
51fd46c
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 21:17
dd54658 to
0868ec4
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 21:29
51fd46c to
828ac31
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 21:29
0868ec4 to
ffd8eb7
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 21:42
828ac31 to
194f960
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 21:42
ffd8eb7 to
770eace
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 21:54
194f960 to
86d9c0f
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 21:54
770eace to
93b30ab
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
force-pushed
the
refactor-cache-drop-legacy-tx-helpers
branch
from
May 22, 2026 23:02
86d9c0f to
364285f
Compare
kalbasit
force-pushed
the
feat-analytics-to-ent
branch
from
May 22, 2026 23:02
93b30ab to
0875a49
Compare
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
kalbasit
added a commit
that referenced
this pull request
May 22, 2026
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
pkg/analytics held the last in-tree consumer of database.Querier outside of test fixtures. The reporter now takes a *database.Client, and the ncps_store_nar_files_total_size_bytes gauge callback issues the SUM via the Ent fluent API with the null-safe sql.NullInt64 unpacking pattern already used elsewhere in the codebase. pkg/ncps/serve.go threads dbClient into analytics.New in place of the legacy db Querier. Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/analytics/analytics.go`:
- Around line 268-270: The aggregation scan struct currently expects a column
alias "sum" via `sql:"sum"` but the query may not be aliasing the aggregate
accordingly; keep the struct definition with Sum sql.NullInt64 `sql:"sum"` and
ensure the ent aggregation call that produces this value uses an explicit alias
(e.g., use ent.As(...) or alias the aggregate as "sum") so
Aggregate(...).Scan(&sums) receives a column named "sum"; also verify the
scanned type (`sql.NullInt64` on the `Sum` field) matches the aggregate type
returned by the query.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d830060a-f8a0-4611-b6cc-d1652ecb36e3
📒 Files selected for processing (2)
pkg/analytics/analytics.gopkg/ncps/serve.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1217 +/- ##
=====================================
Coverage 5.68% 5.68%
=====================================
Files 6 6
Lines 387 387
=====================================
Hits 22 22
Misses 361 361
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pkg/analytics held the last in-tree consumer of database.Querier
outside of test fixtures. The reporter now takes a *database.Client,
and the ncps_store_nar_files_total_size_bytes gauge callback issues
the SUM via the Ent fluent API with the null-safe sql.NullInt64
unpacking pattern already used elsewhere in the codebase.
pkg/ncps/serve.go threads dbClient into analytics.New in place of the
legacy db Querier.
Co-Authored-By: Claude Opus 4.7 [email protected]