feat(backend): immutable cache dir scheme + stale sweep

This commit is contained in:
2026-09-05 00:23:57 +08:00
parent b02ca67d16
commit 4e84a8aeb7
4 changed files with 122 additions and 0 deletions
+18
View File
@@ -262,6 +262,24 @@ func (s *Store) ListBooks(ctx context.Context, libID int64, q, prefix string, us
return out, rows.Err()
}
func (s *Store) BookHashes(ctx context.Context) (map[int64][2]int64, error) {
rows, err := s.P.Query(ctx, "SELECT id, file_size, mod_ts FROM books")
if err != nil {
return nil, err
}
defer rows.Close()
out := map[int64][2]int64{}
for rows.Next() {
var id int64
var v [2]int64
if err := rows.Scan(&id, &v[0], &v[1]); err != nil {
return nil, err
}
out[id] = v
}
return out, rows.Err()
}
// ---------- progress ----------
func (s *Store) UpsertProgress(ctx context.Context, userID, libID int64, bookPath string, locator []byte, percent float64) error {
+14
View File
@@ -77,6 +77,20 @@ func TestBooksDiffLifecycle(t *testing.T) {
}
}
func TestBookHashes(t *testing.T) {
s := setup(t)
ctx := context.Background()
libID, _ := s.CreateLibrary(ctx, "l", "/data/books/l")
bid, _ := s.InsertBook(ctx, libID, "a.cbz", "a", "cbz", 100, 2000, 1)
m, err := s.BookHashes(ctx)
if err != nil {
t.Fatal(err)
}
if v := m[bid]; v[0] != 100 || v[1] != 2000 {
t.Fatalf("bad hashes %+v", v)
}
}
func TestProgressUpsertAndJoin(t *testing.T) {
s := setup(t)
ctx := context.Background()