Repository navigation
feat(cache): convert populateNarInfoFromDatabase to Ent - #1198
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
7476f56 to
d47e51b
Compare
215d89f to
52a4512
Compare
d47e51b to
6caee71
Compare
52a4512 to
0e52ed8
Compare
6caee71 to
b63df34
Compare
0e52ed8 to
17f74d6
Compare
b63df34 to
7eb0409
Compare
17f74d6 to
d8ee4c7
Compare
7eb0409 to
69fd9fc
Compare
d8ee4c7 to
b1c416c
Compare
69fd9fc to
756cb1b
Compare
b1c416c to
3724df5
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 CodeRabbit
WalkthroughThis PR migrates ChangesNarInfo Ent Migration
Sequence Diagram(s)sequenceDiagram
participant Caller
participant getNarInfoFromDatabase
participant withEntTransaction
participant populateNarInfoFromDatabase
participant EntClient
participant EntUpdate
Caller->>getNarInfoFromDatabase: request narinfo
getNarInfoFromDatabase->>withEntTransaction: begin Ent tx
withEntTransaction->>populateNarInfoFromDatabase: call with *ent.Tx
populateNarInfoFromDatabase->>EntClient: Ent query (eager-load refs & sigs)
EntClient-->>populateNarInfoFromDatabase: Ent entity + edges
populateNarInfoFromDatabase->>populateNarInfoFromDatabase: deref nullable fields, parse hashes, parse signatures
alt touch enabled
populateNarInfoFromDatabase->>EntUpdate: Ent update LastAccessedAt (nil or stale handling)
EntUpdate-->>populateNarInfoFromDatabase: update result
end
populateNarInfoFromDatabase-->>withEntTransaction: return NarInfo
withEntTransaction-->>getNarInfoFromDatabase: commit/return
getNarInfoFromDatabase-->>Caller: NarInfo or ErrNotFound
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Labels
🚥 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 |
756cb1b to
7f0de59
Compare
3724df5 to
1a69830
Compare
7f0de59 to
d963c81
Compare
1a69830 to
d394450
Compare
d963c81 to
196e69e
Compare
d394450 to
dfd6326
Compare
§11.2 continuation. Switches the cache's central narinfo-read
helper from the qtx-style Querier closures (sqlc shape: row
fields are sql.Null*, references/signatures fetched in
separate queries by ID) to the Ent fluent API (row fields are
*string/*int64 pointers, references and signatures eager-loaded
in one round-trip via `WithReferences()` / `WithSignatures()`).
Specifically:
- `populateNarInfoFromDatabase(ctx, tx *ent.Tx, hash, touch)`:
- `tx.NarInfo.Query().Where(HashEQ(hash)).WithReferences()
.WithSignatures().Only(ctx)` replaces three separate
Querier calls (GetNarInfoByHash + GetNarInfoReferences +
GetNarInfoSignatures). One query, one round-trip.
- `ent.IsNotFound(err)` replaces `database.IsNotFoundError`.
- sql.NullString/NullInt64 reads (`x.URL.Valid`, `x.URL.String`,
`x.FileSize.Int64`, …) become pointer dereferences via
`derefStringPtr`/`derefInt64Ptr` helpers introduced in this
commit. `parseValidHashPtr` is the *string counterpart to
`parseValidHash` and replaces it (the sql.NullString
version was the helper's only caller, so removed).
- Touch logic (`if time.Since(LastAccessedAt) >
recordAgeIgnoreTouch`) now reads `*time.Time` directly and
calls `tx.NarInfo.Update().Where(HashEQ(hash))
.SetLastAccessedAt(time.Now()).Save(ctx)` instead of the
sqlc-generated `TouchNarInfo`.
- The one caller `getNarInfoFromDatabase` switches from
`c.withTransaction(ctx, op, func(qtx database.Querier))` to
`c.withEntTransaction(ctx, op, func(tx *ent.Tx))`, the helper
added in `feat-cache-with-ent-transaction`.
Both `parseValidHashPtr` and the deref helpers are written to
be reusable for upcoming §11 conversions (PutNarInfo,
GetNarFile, fsck) that face the same null-shape translation.
Behaviour-preserving by construction:
- The eager-load result iteration order matches sqlc's. For
references it's narinfo_references.id ASC because the join
uses the row order; the prior GetNarInfoReferences query
ordered by reference's PRIMARY KEY (id) too, so the slice
is identical.
- Touch is gated by the same recordAgeIgnoreTouch threshold
and emits an UPDATE only when stale.
- "Stub" narinfos (URL NULL/empty) still return
storage.ErrNotFound.
Verified by `go test -race ./pkg/cache/...` against SQLite +
Postgres + MySQL + Redis. Lint clean.
dfd6326 to
6589260
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1198 +/- ##
=====================================
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:
|
§11.2 continuation. Switches the cache's central narinfo-read
helper from the qtx-style Querier closures (sqlc shape: row
fields are sql.Null*, references/signatures fetched in
separate queries by ID) to the Ent fluent API (row fields are
*string/*int64 pointers, references and signatures eager-loaded
in one round-trip via
WithReferences()/WithSignatures()).Specifically:
populateNarInfoFromDatabase(ctx, tx *ent.Tx, hash, touch):tx.NarInfo.Query().Where(HashEQ(hash)).WithReferences() .WithSignatures().Only(ctx)replaces three separateQuerier calls (GetNarInfoByHash + GetNarInfoReferences +
GetNarInfoSignatures). One query, one round-trip.
ent.IsNotFound(err)replacesdatabase.IsNotFoundError.x.URL.Valid,x.URL.String,x.FileSize.Int64, …) become pointer dereferences viaderefStringPtr/derefInt64Ptrhelpers introduced in thiscommit.
parseValidHashPtris the *string counterpart toparseValidHashand replaces it (the sql.NullStringversion was the helper's only caller, so removed).
if time.Since(LastAccessedAt) > recordAgeIgnoreTouch) now reads*time.Timedirectly andcalls
tx.NarInfo.Update().Where(HashEQ(hash)) .SetLastAccessedAt(time.Now()).Save(ctx)instead of thesqlc-generated
TouchNarInfo.The one caller
getNarInfoFromDatabaseswitches fromc.withTransaction(ctx, op, func(qtx database.Querier))toc.withEntTransaction(ctx, op, func(tx *ent.Tx)), the helperadded in
feat-cache-with-ent-transaction.Both
parseValidHashPtrand the deref helpers are written tobe reusable for upcoming §11 conversions (PutNarInfo,
GetNarFile, fsck) that face the same null-shape translation.
Behaviour-preserving by construction:
references it's narinfo_references.id ASC because the join
uses the row order; the prior GetNarInfoReferences query
ordered by reference's PRIMARY KEY (id) too, so the slice
is identical.
and emits an UPDATE only when stale.
storage.ErrNotFound.
Verified by
go test -race ./pkg/cache/...against SQLite +Postgres + MySQL + Redis. Lint clean.