Repository navigation
feat(cache): convert remaining GetNarInfo* read paths to Ent - #1199
Conversation
d8ee4c7 to
b1c416c
Compare
b8748eb to
15cfae6
Compare
b1c416c to
3724df5
Compare
15cfae6 to
fca78b0
Compare
📝 WalkthroughSummary by CodeRabbit
WalkthroughMigrates narinfo DB access in pkg/cache from sqlc/legacy queries to Ent ORM (fetch/touch, validation/fix, pinned-closure traversal) and marks the related migration checklist item complete. ChangesCache layer Ent ORM migration
Estimated code review effort: Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
3724df5 to
1a69830
Compare
fca78b0 to
3ab6f68
Compare
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/cache/cache.go`:
- Around line 4353-4386: The helper checkAndFixNarInfoNoCompression currently
only clears FileSize/FileHash when they are non-zero/non-empty; change it to
clear any non-NULL value (including 0 and "") so rows with zero/empty values are
normalized to NULL. Specifically, in checkAndFixNarInfoNoCompression inspect
niRow.FileSize and niRow.FileHash for != nil (not for != 0 / != ""), log the
current value, and call c.withEntTransaction (same "fixNarInfoFileSizeToNull" /
"fixNarInfoFileHashToNull" update blocks that use
tx.NarInfo.Update().Where(entnarinfo.HashEQ(hash)).ClearFileSize()/ClearFileHash().Save(ctx))
to clear them unconditionally when non-nil.
🪄 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: 8680b49b-aa22-49fc-9827-bb5fd312a180
📒 Files selected for processing (2)
openspec/changes/migrate-to-ent-and-atlas/tasks.mdpkg/cache/cache.go
1a69830 to
d394450
Compare
3ab6f68 to
9949687
Compare
d394450 to
dfd6326
Compare
9949687 to
8f24530
Compare
dfd6326 to
6589260
Compare
8f24530 to
8d9fd40
Compare
§11.2 completion. Three call sites that were left unconverted
by the prior commits because they read row fields downstream
(the "row-shape cascade") and so couldn't move in isolation.
All three now run through the Ent fluent API.
- `getNarInfoFromStore` (line 3699): inside-tx GetNarInfoByHash
+ TouchNarInfo path. Switched from c.withTransaction
(qtx-style) to c.withEntTransaction (Ent-tx style). The
TouchNarInfo call becomes
`tx.NarInfo.Update().Where(HashEQ).SetLastAccessedAt(time.Now())
.Save(ctx)`, matching the same pattern populateNarInfoFromDatabase
uses for touch.
- `CheckAndFixNarInfo` + `checkAndFixNarInfoNoCompression` (line
4285): consumes the entire narinfo row to inspect URL,
FileSize, FileHash. Now reads from `*ent.NarInfo` (pointer
fields) via the new `derefInt64Ptr` helper and direct
pointer dereferences. The two "fix to NULL" paths in
checkAndFixNarInfoNoCompression use
`tx.NarInfo.Update().ClearFileSize()` / `.ClearFileHash()`
to set the columns NULL — Ent's idiomatic way to do what
`UpdateNarInfoFileSize`/`UpdateNarInfoFileHash` did with
sql.NullInt64/sql.NullString{Valid: false}.
- Closure-pinning BFS (line 7002): combines GetNarInfoByHash +
GetNarInfoReferences(narinfo.ID) into one round-trip via
`tx.NarInfo.Query().Where(HashEQ).WithReferences().Only(ctx)`,
iterating `ni.Edges.References` directly. Avoids the surrogate-id
lookup the legacy path needed (sqlc's GetNarInfoReferences
takes narinfo_id, which is irrelevant under Ent's edge model).
After this commit no `c.db.GetNarInfo*` or `qtx.GetNarInfo*`
call site remains in pkg/cache — §11.2 is complete and tasks.md
gets ticked. The same downstream-row-shape pattern (deref helpers
+ Ent UpdateOne mutators) will be reused for §11.3 (PutNarInfo)
and §11.4 (GetNarFile).
`go test -race ./pkg/cache/...` passes against SQLite + Postgres +
MySQL + Redis. Lint clean.
§11.2 (Convert GetNarInfo* paths in pkg/cache/ to Ent fluent API) finished across feat-cache-getnarinfo-to-ent, feat-cache- populate-narinfo-ent, and feat-cache-getnarinfo-ent-finish. No `c.db.GetNarInfo*` or `qtx.GetNarInfo*` call site remains in pkg/cache.
8d9fd40 to
ac82cc7
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
pkg/cache/cache.go (1)
4353-4388:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winClear non-NULL
compression=nonemetadata even when it is zero/empty.Line 4355 and Line 4374 only repair
file_size/file_hashwhen the stored value is non-zero / non-empty. Rows that already contain0or""stay non-NULL forever, so this repair never fully normalizes legacy data.Suggested fix
- if niRow.FileSize != nil && *niRow.FileSize != 0 { + if niRow.FileSize != nil { zerolog.Ctx(ctx). Info(). Int64("current_size", *niRow.FileSize). Msg("mismatch detected for compression=none, fixing narinfo file size to NULL") @@ - if niRow.FileHash != nil && *niRow.FileHash != "" { + if niRow.FileHash != nil { zerolog.Ctx(ctx). Info(). Str("current_file_hash", *niRow.FileHash). Msg("mismatch detected for compression=none, fixing narinfo file hash to NULL")🤖 Prompt for 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. In `@pkg/cache/cache.go` around lines 4353 - 4388, The checkAndFixNarInfoNoCompression function only clears FileSize/FileHash when values are non-zero/non-empty, leaving zero or empty pointers non-NULL; change the guards to clear whenever the pointer is non-nil (i.e., use niRow.FileSize != nil and niRow.FileHash != nil) so rows with 0 or "" get set to NULL too, keep the existing logging (dereference safely) and the withEntTransaction calls (fixNarInfoFileSizeToNull, fixNarInfoFileHashToNull) as-is to perform the update.
🤖 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.
Duplicate comments:
In `@pkg/cache/cache.go`:
- Around line 4353-4388: The checkAndFixNarInfoNoCompression function only
clears FileSize/FileHash when values are non-zero/non-empty, leaving zero or
empty pointers non-NULL; change the guards to clear whenever the pointer is
non-nil (i.e., use niRow.FileSize != nil and niRow.FileHash != nil) so rows with
0 or "" get set to NULL too, keep the existing logging (dereference safely) and
the withEntTransaction calls (fixNarInfoFileSizeToNull,
fixNarInfoFileHashToNull) as-is to perform the update.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e55be3f1-f809-45b9-bcef-266338172c19
📒 Files selected for processing (2)
openspec/changes/migrate-to-ent-and-atlas/tasks.mdpkg/cache/cache.go
✅ Files skipped from review due to trivial changes (1)
- openspec/changes/migrate-to-ent-and-atlas/tasks.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1199 +/- ##
=====================================
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:
|
feat(cache): convert remaining GetNarInfo* read paths to Ent
§11.2 completion. Three call sites that were left unconverted
by the prior commits because they read row fields downstream
(the "row-shape cascade") and so couldn't move in isolation.
All three now run through the Ent fluent API.
getNarInfoFromStore(line 3699): inside-tx GetNarInfoByHash(qtx-style) to c.withEntTransaction (Ent-tx style). The
TouchNarInfo call becomes
tx.NarInfo.Update().Where(HashEQ).SetLastAccessedAt(time.Now()) .Save(ctx), matching the same pattern populateNarInfoFromDatabaseuses for touch.
CheckAndFixNarInfo+checkAndFixNarInfoNoCompression(line4285): consumes the entire narinfo row to inspect URL,
FileSize, FileHash. Now reads from
*ent.NarInfo(pointerfields) via the new
derefInt64Ptrhelper and directpointer dereferences. The two "fix to NULL" paths in
checkAndFixNarInfoNoCompression use
tx.NarInfo.Update().ClearFileSize()/.ClearFileHash()to set the columns NULL — Ent's idiomatic way to do what
UpdateNarInfoFileSize/UpdateNarInfoFileHashdid withsql.NullInt64/sql.NullString{Valid: false}.
Closure-pinning BFS (line 7002): combines GetNarInfoByHash +
GetNarInfoReferences(narinfo.ID) into one round-trip via
tx.NarInfo.Query().Where(HashEQ).WithReferences().Only(ctx),iterating
ni.Edges.Referencesdirectly. Avoids the surrogate-idlookup the legacy path needed (sqlc's GetNarInfoReferences
takes narinfo_id, which is irrelevant under Ent's edge model).
After this commit no
c.db.GetNarInfo*orqtx.GetNarInfo*call site remains in pkg/cache — §11.2 is complete and tasks.md
gets ticked. The same downstream-row-shape pattern (deref helpers
and §11.4 (GetNarFile).
go test -race ./pkg/cache/...passes against SQLite + Postgres +MySQL + Redis. Lint clean.
docs(openspec): mark §11.2 tasks complete
§11.2 (Convert GetNarInfo* paths in pkg/cache/ to Ent fluent
API) finished across feat-cache-getnarinfo-to-ent, feat-cache-
populate-narinfo-ent, and feat-cache-getnarinfo-ent-finish. No
c.db.GetNarInfo*orqtx.GetNarInfo*call site remainsin pkg/cache.