More efficient garbage collection of cache.
Iterates backwards from first entry of this generation, and forward from last entry.
This commit is contained in:
parent
914e30365e
commit
b801954599
@ -11,6 +11,8 @@ use log::info;
|
||||
use log::warn;
|
||||
use photos::schemas::Album;
|
||||
use photos::schemas::MediaItem;
|
||||
use rocksdb::Direction;
|
||||
use rocksdb::IteratorMode;
|
||||
use rocksdb::DB;
|
||||
|
||||
// Used to ensure DB is invalidated after schema changes.
|
||||
@ -47,7 +49,16 @@ impl Library {
|
||||
}
|
||||
fn gc(generation: &str, db: &DB) -> Result<(), rocksdb::Error> {
|
||||
let gen = format!("{}/", generation);
|
||||
for (k, _v) in db.iterator(rocksdb::IteratorMode::Start) {
|
||||
// '0' is the next character after '/', so iterator's starting there would be after the
|
||||
// last `gen` entry.
|
||||
let next_gen = format!("{}0", generation);
|
||||
for (k, _v) in db.iterator(IteratorMode::From(gen.as_bytes(), Direction::Reverse)) {
|
||||
if !k.starts_with(gen.as_bytes()) {
|
||||
info!("deleting stale key: {}", String::from_utf8_lossy(&k));
|
||||
db.delete(k)?;
|
||||
}
|
||||
}
|
||||
for (k, _v) in db.iterator(IteratorMode::From(next_gen.as_bytes(), Direction::Forward)) {
|
||||
if !k.starts_with(gen.as_bytes()) {
|
||||
info!("deleting stale key: {}", String::from_utf8_lossy(&k));
|
||||
db.delete(k)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user