Skip to content

feat: implement deletion, JSON encoding, and query optimizations for SQLite storage#536

Merged
dundee merged 2 commits intomasterfrom
implement-sqlite-deletion-and-json-encoding-v2-11755656939269439320
Apr 1, 2026
Merged

feat: implement deletion, JSON encoding, and query optimizations for SQLite storage#536
dundee merged 2 commits intomasterfrom
implement-sqlite-deletion-and-json-encoding-v2-11755656939269439320

Conversation

@dundee
Copy link
Copy Markdown
Owner

@dundee dundee commented Apr 1, 2026

Summary

Implements the previously stubbed-out RemoveFile, RemoveFileByName, and
EncodeJSON methods for the SQLite storage backend, along with performance
improvements to the deletion path and query indexing.

Changes

Deletion (RemoveFile, RemoveFileByName)

  • Recursive CTE deletes an item and all its descendants in a single SQL statement
  • Ancestor stats (size, usage, item_count) are updated per-ancestor within the
    same transaction, using a single in-memory walk — no redundant recursive CTE
    for ancestor updates
  • In-memory stats are only applied after the transaction commits, preventing
    DB/memory inconsistency on rollback
  • GetParentLocked() avoids deadlock by traversing cached parents without
    acquiring storage.m.RLock while storage.m.Lock is held
  • GetChildByName enables RemoveFileByName to look up children by name

JSON encoding (EncodeJSON)

  • encodeDirJSON recursively encodes directories and their children
  • encodeFileJSON encodes files including hard-link and non-regular flags
  • Matches the output format of the in-memory Dir/File EncodeJSON methods

Query optimizations

  • Added composite index (parent_id, name) for GetChildByName lookups
  • Removed unused DeleteItem public method (its logic is covered by the
    internal deleteItemTree)

Implemented missing functionality for `SqliteItem` and `SqliteStorage`,
specifically:
- `RemoveFile` and `RemoveFileByName` for atomic item deletion and
  ancestor stat updates in the database.
- `EncodeJSON` for exporting analysis data in ncdu-compatible format.
- `RemoveItemAndUpdateStats` and `GetChildByName` helpers in
  `SqliteStorage` for efficient database operations using recursive CTEs
  and transactions.
- Memory-state propagation in `RemoveFile` to keep loaded ancestors
  synchronized.
- Updated `pkg/analyze/sqlite_test.go` with tests for the new functionality.

Co-authored-by: dundee <27106+dundee@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 66.82692% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.90%. Comparing base (8f8a6bc) to head (a3e11c5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/analyze/sqlite.go 66.82% 46 Missing and 23 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #536      +/-   ##
==========================================
+ Coverage   84.36%   85.90%   +1.53%     
==========================================
  Files          52       52              
  Lines        5566     5774     +208     
==========================================
+ Hits         4696     4960     +264     
+ Misses        722      640      -82     
- Partials      148      174      +26     

☔ 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.

@dundee dundee force-pushed the implement-sqlite-deletion-and-json-encoding-v2-11755656939269439320 branch from a3e11c5 to 8412e3d Compare April 1, 2026 14:10
@dundee dundee changed the title Implement deletion and JSON encoding for SQLite storage Implement deletion, JSON encoding, and query optimizations for SQLite storage Apr 1, 2026
@dundee dundee changed the title Implement deletion, JSON encoding, and query optimizations for SQLite storage feat: implement deletion, JSON encoding, and query optimizations for SQLite storage Apr 1, 2026
@dundee dundee merged commit 011eca5 into master Apr 1, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant