Skip to content

feat(cache): convert NarInfo/NarFile delete paths to Ent - #1201

Merged
kalbasit merged 1 commit into
mainfrom
feat-cache-delete-narinfo-ent
May 22, 2026
Merged

kalbasit merged 1 commit into
mainfrom
feat-cache-delete-narinfo-ent

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

§11.3 partial. The simple delete sites in pkg/cache convert
cleanly without the UPSERT cascade that storeInDatabase
will need; landing them in a separate commit keeps each diff
reviewable.

Converted:

  • deleteNarInfoFromStore (line 4778):
    c.db.DeleteNarInfoByHash →
    c.dbClient.Ent().NarInfo.Delete().Where(HashEQ(hash)).Exec(ctx).
  • purgeNarInfo (line 4076):
    switched the wrapper from c.withTransaction(... qtx ...)
    to c.withEntTransaction(... tx *ent.Tx ...). The two
    inside-tx deletes (NarInfo + NarFile) become Ent Delete
    builders with the same predicates the sqlc query used
    (hash for NarInfo; hash + compression + query for NarFile).

Behaviour preservation:

  • The cascading deletes the comment notes (references,
    signatures, narinfo_nar_files links) are still handled by
    the database-level ON DELETE CASCADE the §8 bridge
    migration set up. Ent's Delete builder doesn't need to do
    anything beyond DELETE FROM narinfos WHERE hash = ?.

Deferred to follow-up commits in §11.3:

  • storeInDatabase and the second PutNarInfo helper (line
    4631) — both do a conditional UPSERT
    (ON CONFLICT (hash) DO UPDATE ... WHERE url IS NULL) plus
    bulk reference / signature inserts plus a NarFile UPSERT
    plus a NarFile<->NarInfo link. Substantial; their own
    commit.
  • DeleteNarInfoByID inside the LRU eviction loop (line
    5535) — sits in a larger withTransaction block whose
    surrounding qtx calls belong to §11.5 (orphan cleanup).
    Leaving it qtx-style until that whole block converts as a
    unit.

go test -race ./pkg/cache/... passes against SQLite + Postgres

  • MySQL + Redis. Lint clean.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. go Pull requests that update go code labels May 21, 2026
@kalbasit

kalbasit commented May 21, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

This was referenced May 21, 2026
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from e5d9040 to 435ce97 Compare May 22, 2026 06:47
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from e9c62db to b49741f Compare May 22, 2026 07:06
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from 435ce97 to e73fdb1 Compare May 22, 2026 07:06
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from b49741f to b5e2e6c Compare May 22, 2026 18:07
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from e73fdb1 to ff60258 Compare May 22, 2026 18:07
@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@kalbasit has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 56 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c09385b-4fb3-42d6-8b90-3eedde4ae57e

📥 Commits

Reviewing files that changed from the base of the PR and between 44acb3d and 2cfb023.

📒 Files selected for processing (1)
  • pkg/cache/cache.go
📝 Walkthrough

Walkthrough

Two deletion code paths in the cache package migrate from legacy database.Querier helpers to Ent ORM. purgeNarInfo switches to withEntTransaction for atomic NarInfo and conditional NarFile deletion. deleteNarInfoFromStore replaces the Querier delete with an Ent where-clause delete, preserving all surrounding storage-backend cleanup.

Changes

NarInfo Deletion Ent Migration

Layer / File(s) Summary
NarInfo and NarFile deletion via Ent
pkg/cache/cache.go
purgeNarInfo uses withEntTransaction to delete NarInfo by hash and optionally delete NarFile by hash, compression, and query. deleteNarInfoFromStore replaces c.db.DeleteNarInfoByHash with c.dbClient.Ent().NarInfo.Delete().Where(entnarinfo.HashEQ(hash)). Both preserve surrounding legacy narinfo/NAR store cleanup logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • kalbasit/ncps#1193: Overlapping Ent migration in deleteNarInfoFromStore and related NarInfo database operations.
  • kalbasit/ncps#1194: Introduces the withEntTransaction helper that wraps deadlock-retry logic used by purgeNarInfo in this PR.

Suggested labels

enhancement, size:M

Poem

🐰 Two deletion paths now dance with Ent's grace,
NarInfo rows swept clean from their place,
Legacy helpers fade to the past,
This refactored cache code's built to last! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(cache): convert NarInfo/NarFile delete paths to Ent' directly and specifically describes the main change: migrating database deletion logic from sqlc to Ent for NarInfo and NarFile operations.
Description check ✅ Passed The description provides detailed context about the changes, referencing the specific functions modified (deleteNarInfoFromStore, purgeNarInfo), the conversion approach, behavior preservation details, and deferred work—all directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from b5e2e6c to fc295e1 Compare May 22, 2026 19:02
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from ff60258 to 65ea5a4 Compare May 22, 2026 19:02
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from fc295e1 to 96e4a3d Compare May 22, 2026 20:44
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from 65ea5a4 to e4ebb15 Compare May 22, 2026 20:44
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from 96e4a3d to ab5cee7 Compare May 22, 2026 20:51
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from e4ebb15 to 71fda8d Compare May 22, 2026 20:51
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from ab5cee7 to 0604b80 Compare May 22, 2026 21:04
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from 71fda8d to 32d47d0 Compare May 22, 2026 21:04
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from 0604b80 to a326646 Compare May 22, 2026 21:16
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from 32d47d0 to bf73661 Compare May 22, 2026 21:16
@kalbasit
kalbasit force-pushed the chore-ent-enable-sql-upsert branch from a326646 to 088f9bb Compare May 22, 2026 21:29
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from bf73661 to 44acb3d Compare May 22, 2026 21:29
Base automatically changed from chore-ent-enable-sql-upsert to main May 22, 2026 21:41
§11.3 partial. The simple delete sites in pkg/cache convert
cleanly without the UPSERT cascade that storeInDatabase
will need; landing them in a separate commit keeps each diff
reviewable.

Converted:

- `deleteNarInfoFromStore` (line 4778):
  `c.db.DeleteNarInfoByHash` →
  `c.dbClient.Ent().NarInfo.Delete().Where(HashEQ(hash)).Exec(ctx)`.
- `purgeNarInfo` (line 4076):
  switched the wrapper from `c.withTransaction(... qtx ...)`
  to `c.withEntTransaction(... tx *ent.Tx ...)`. The two
  inside-tx deletes (NarInfo + NarFile) become Ent Delete
  builders with the same predicates the sqlc query used
  (hash for NarInfo; hash + compression + query for NarFile).

Behaviour preservation:

- The cascading deletes the comment notes (references,
  signatures, narinfo_nar_files links) are still handled by
  the database-level ON DELETE CASCADE the §8 bridge
  migration set up. Ent's Delete builder doesn't need to do
  anything beyond DELETE FROM narinfos WHERE hash = ?.

Deferred to follow-up commits in §11.3:

- `storeInDatabase` and the second PutNarInfo helper (line
  4631) — both do a conditional UPSERT
  (`ON CONFLICT (hash) DO UPDATE ... WHERE url IS NULL`) plus
  bulk reference / signature inserts plus a NarFile UPSERT
  plus a NarFile<->NarInfo link. Substantial; their own
  commit.
- `DeleteNarInfoByID` inside the LRU eviction loop (line
  5535) — sits in a larger withTransaction block whose
  surrounding qtx calls belong to §11.5 (orphan cleanup).
  Leaving it qtx-style until that whole block converts as a
  unit.

`go test -race ./pkg/cache/...` passes against SQLite + Postgres
+ MySQL + Redis. Lint clean.
@kalbasit
kalbasit force-pushed the feat-cache-delete-narinfo-ent branch from 44acb3d to 2cfb023 Compare May 22, 2026 21:41
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 22, 2026
@kalbasit
kalbasit enabled auto-merge (squash) May 22, 2026 21:42
@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.68%. Comparing base (964dd78) to head (2cfb023).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1201   +/-   ##
=====================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit merged commit 77c522a into main May 22, 2026
18 checks passed
@kalbasit
kalbasit deleted the feat-cache-delete-narinfo-ent branch May 22, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code merge-stack size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant