Skip to content

GC for database - #1474

Draft
TheAwiteb wants to merge 4 commits into
nostrdevkit:masterfrom
TheAwiteb:dbs-gc
Draft

TheAwiteb wants to merge 4 commits into
nostrdevkit:masterfrom
TheAwiteb:dbs-gc

Conversation

@TheAwiteb

Copy link
Copy Markdown
Member

Description

A way to clean up database garbage. It has two parts: the database part and the database user part (where the user can be a client or a relay).

The database handles the deletion, and the user manages when and how to collect the garbage. That makes it kinda flexible, crate users don't have to depend on the SDK to clean garbage, so they can handle it themselves however they want.

Also, I named it NostrDatabase::collect_garbage instead of naming it specifically after expired events, because a user might wrap our database or implement their own and consider other things garbage too. It just makes more sense to name it like this.

Checklist

  • I followed the contribution guidelines
  • I updated the relevant CHANGELOG.md (if applicable)
  • I understand and can explain all code in this PR

…bage`

Added the `collect_garbage` function to the `NostrDatabase` trait. This
gives the user (client or relay) direct control over garbage collection
timing, removing the need for an automatic runtime on each database.

Signed-off-by: Awiteb <a@4rs.nl>
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.54217% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
database/nostr-lmdb/src/store/ingester.rs 58.33% 10 Missing ⚠️
database/nostr-lmdb/src/store/lmdb/mod.rs 88.57% 8 Missing ⚠️
database/nostr-database/src/lib.rs 0.00% 3 Missing ⚠️
database/nostr-ndb/src/lib.rs 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Ensure expired events are correctly removed when calling
`NostrDatabase::collect_garbage`. The test saves an expired event and
verifies it gets deleted after garbage collection.

Signed-off-by: Awiteb <a@4rs.nl>
Adds garbage collection to delete expired events. This implements the
`event_expiration` feature, making the database track and manage event
expiration.

- Creates a new `expirations` database to track events with expiration timestamps
- Adds an `is_indexable` field to `TagIndexKeySet` because the
  `expiration` tag is non-indexable
- Bumps the database version to 3 to migrate existing events and
  populate the expirations tracker

Signed-off-by: Awiteb <a@4rs.nl>
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