Skip to content

Commit

Permalink
delete all paste related data on expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs committed Mar 26, 2022
1 parent 0977ade commit 7c9a48f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ impl Database {
}

pub fn enforce_paste_expirations(&self) -> DatabaseResult<()> {
let tree = self.db.open_tree("expirations")?;
let expirations_tree = self.db.open_tree("expirations")?;
let views_tree = self.db.open_tree("views")?;;

let start_expiry = 0u128.to_be_bytes();
let unix_now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let end_expiry = unix_now.as_nanos().to_be_bytes();

for (_, paste_id) in tree.range(start_expiry..end_expiry).flatten() {
self.db.remove(paste_id)?;
for (expiry, paste_id) in expirations_tree.range(start_expiry..end_expiry).flatten() {
self.db.remove(&paste_id)?;
views_tree.remove(&paste_id)?;
expirations_tree.remove(expiry)?;
}

Ok(())
Expand Down

0 comments on commit 7c9a48f

Please sign in to comment.