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
+17 -4
View File
@@ -95,9 +95,16 @@ func TestCleanup_ExpiredStorage(t *testing.T) {
}
if err := app.DB.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(DBBucketName))
bFiles := tx.Bucket([]byte(DBBucketName))
bIndex := tx.Bucket([]byte(DBBucketIndexName))
data, _ := json.Marshal(expiredMeta)
return b.Put([]byte(filename), data)
if err := bFiles.Put([]byte(filename), data); err != nil {
return err
}
indexKey := []byte(expiredMeta.ExpiresAt.Format(time.RFC3339) + "_" + filename)
return bIndex.Put(indexKey, []byte(filename))
}); err != nil {
t.Fatalf("DB Update failed: %v", err)
}
@@ -109,10 +116,16 @@ func TestCleanup_ExpiredStorage(t *testing.T) {
}
if err := app.DB.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(DBBucketName))
if v := b.Get([]byte(filename)); v != nil {
bFiles := tx.Bucket([]byte(DBBucketName))
if v := bFiles.Get([]byte(filename)); v != nil {
t.Error("Cleanup failed to remove metadata")
}
bIndex := tx.Bucket([]byte(DBBucketIndexName))
indexKey := []byte(expiredMeta.ExpiresAt.Format(time.RFC3339) + "_" + filename)
if v := bIndex.Get(indexKey); v != nil {
t.Error("Cleanup failed to remove index entry")
}
return nil
}); err != nil {
t.Fatalf("DB View failed: %v", err)