perf(storage)!: optimize cleanup with secondary index

BREAKING CHANGE: This change requires a fresh database. Existing
databases will lack the index, and the cleanup routine will not function
correctly for pre-existing files.

Signed-off-by: skidoodle <contact@albert.lol>
This commit is contained in:
2026-01-18 22:10:07 +01:00
parent e18be18029
commit d18ef48bd4
5 changed files with 73 additions and 27 deletions
+13 -2
View File
@@ -29,10 +29,12 @@ func TestInitDB(t *testing.T) {
}
err = db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(DBBucketName))
if b == nil {
if b := tx.Bucket([]byte(DBBucketName)); b == nil {
t.Errorf("Bucket '%s' was not created", DBBucketName)
}
if b := tx.Bucket([]byte(DBBucketIndexName)); b == nil {
t.Errorf("Bucket '%s' was not created", DBBucketIndexName)
}
return nil
})
if err != nil {
@@ -85,6 +87,15 @@ func TestDB_MetadataLifecycle(t *testing.T) {
if meta.ExpiresAt.Before(time.Now()) {
t.Error("Expiration time is in the past")
}
bIndex := tx.Bucket([]byte(DBBucketIndexName))
indexKey := []byte(meta.ExpiresAt.Format(time.RFC3339) + "_" + fileID)
if val := bIndex.Get(indexKey); val == nil {
t.Error("Index entry not found")
} else if string(val) != fileID {
t.Errorf("Index value mismatch: want %s, got %s", fileID, string(val))
}
return nil
})
if err != nil {