Repository navigation
feat(cache): convert non-tx GetNarInfo* lookups to Ent - #1193
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
a6b6331 to
753ab18
Compare
2317fcd to
8f98494
Compare
753ab18 to
2c3ae9a
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbitRelease Notes
Walkthrough
ChangesEnt Client Migration in Cache Service
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 |
8f98494 to
f06e4ff
Compare
2c3ae9a to
51e7fb8
Compare
f06e4ff to
786cdd9
Compare
51e7fb8 to
6c3b640
Compare
786cdd9 to
f816b5d
Compare
6c3b640 to
22010ad
Compare
f816b5d to
1b26d1f
Compare
22010ad to
33fa5e8
Compare
1b26d1f to
419453f
Compare
33fa5e8 to
7537892
Compare
419453f to
28d20fc
Compare
7537892 to
2c22541
Compare
§11.2 partial: convert the GetNarInfo* call sites in pkg/cache/cache.go that don't sit inside the legacy *sql.Tx-based transaction wrapper and don't cascade into sqlc-row-shape consumers. Converted (5 sites): - `GetNarInfoCount` → `dbClient.Ent().NarInfo.Query().Count(ctx)` (and the metrics observer now casts the int result to int64). - `GetNarInfoURLByNarFileHash` (a 3-table join through narinfo_nar_files → nar_files) → an `entnarinfo.HasNarInfoNarFilesWith (entnarinfonarfile.HasNarFileWith(...))` predicate. The result shape changes from `sql.NullString` to a `*ent.NarInfo` whose `URL *string` field is read directly. - `GetNarInfoHashByNarURL` → `Query().Where(URL(...)).First(ctx)`, with `ni.Hash` taking the place of the prior string return. - `GetNarInfoHashesByURL` → `Query().Where(URL(...)).All(ctx)`, iterating `ni.Hash` instead of the prior `[]string` slice. - `deleteNarInfoFromStore`'s existence-check + `PinClosure`'s pre-pin existence check both use `Query().Where(HashEQ(hash)).First(ctx)` with `ent.IsNotFound(err)` replacing `database.IsNotFoundError`. Deferred (still on the original `c.db`/`qtx` API): - `CheckAndFixNarInfo` and `lookupNarInfoForFix` (line 4282 area) cascade into `niRow.URL.Valid`/`niRow.FileSize.Int64` consumers and into `checkAndFixNarInfoNoCompression`. That conversion needs to flow row shape changes through several helpers; left for a follow-up commit. - The closure-pinning narinfo + references lookup (lines 6897, 6907) reads `ni.ID` and feeds it back into `GetNarInfoReferences`. Same row-shape cascade — follow-up. - Every `qtx.GetNarInfo*` site inside `c.executeTransaction` blocks (~6 sites) needs the transaction wrapper to first switch from `func(qtx database.Querier) error` to `func(tx *ent.Tx) error`. That's an infrastructure change pre-requisite, also follow-up. Imports: adds `ent`, `entnarfile`, `entnarinfo`, `entnarinfonarfile`. The legacy `database` import stays — most of pkg/cache still references it. Full -race test suite passes on SQLite + Postgres + MySQL with the deps stack running. Lint clean.
2c22541 to
38fa3fa
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1193 +/- ##
=====================================
Coverage 4.94% 4.94%
=====================================
Files 6 6
Lines 445 445
=====================================
Hits 22 22
Misses 419 419
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
§11.2 partial: convert the GetNarInfo* call sites in
pkg/cache/cache.go that don't sit inside the legacy
*sql.Tx-based transaction wrapper and don't cascade into
sqlc-row-shape consumers.
Converted (5 sites):
GetNarInfoCount→dbClient.Ent().NarInfo.Query().Count(ctx)(and the metrics observer now casts the int result to int64).
GetNarInfoURLByNarFileHash(a 3-table join throughnarinfo_nar_files → nar_files) → an
entnarinfo.HasNarInfoNarFilesWith (entnarinfonarfile.HasNarFileWith(...))predicate. The resultshape changes from
sql.NullStringto a*ent.NarInfowhoseURL *stringfield is read directly.GetNarInfoHashByNarURL→Query().Where(URL(...)).First(ctx),with
ni.Hashtaking the place of the prior string return.GetNarInfoHashesByURL→Query().Where(URL(...)).All(ctx),iterating
ni.Hashinstead of the prior[]stringslice.deleteNarInfoFromStore's existence-check +PinClosure'spre-pin existence check both use
Query().Where(HashEQ(hash)).First(ctx)withent.IsNotFound(err)replacingdatabase.IsNotFoundError.Deferred (still on the original
c.db/qtxAPI):CheckAndFixNarInfoandlookupNarInfoForFix(line 4282area) cascade into
niRow.URL.Valid/niRow.FileSize.Int64consumers and into
checkAndFixNarInfoNoCompression. Thatconversion needs to flow row shape changes through several
helpers; left for a follow-up commit.
6907) reads
ni.IDand feeds it back intoGetNarInfoReferences. Same row-shape cascade — follow-up.qtx.GetNarInfo*site insidec.executeTransactionblocks (~6 sites) needs the transaction wrapper to first
switch from
func(qtx database.Querier) errortofunc(tx *ent.Tx) error. That's an infrastructure changepre-requisite, also follow-up.
Imports: adds
ent,entnarfile,entnarinfo,entnarinfonarfile. The legacydatabaseimport stays — mostof pkg/cache still references it.
Full -race test suite passes on SQLite + Postgres + MySQL with
the deps stack running. Lint clean.