mirror of
https://github.com/NotAShelf/stash.git
synced 2026-04-13 06:23:47 +00:00
watch: implement soft-delete behaviour for expired entries
The previous `--expire-after` flag behave more like *delete* after rather than *expire*. This fixes that, and changes the behaviour to excluding expired entries from list commands and already-marked expired entries from expiration queue. Updates log messages accordingly. Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ib162dff3a76e23edcdfbd1af13b01b916a6a6964
This commit is contained in:
parent
d40b547c07
commit
b070d4d93d
1 changed files with 9 additions and 11 deletions
|
|
@ -107,23 +107,17 @@ impl WatchCommand for SqliteClipboardDb {
|
||||||
smol::block_on(async {
|
smol::block_on(async {
|
||||||
log::info!("Starting clipboard watch daemon");
|
log::info!("Starting clipboard watch daemon");
|
||||||
|
|
||||||
// Cleanup any already-expired entries on startup
|
|
||||||
if let Ok(count) = self.cleanup_expired() {
|
|
||||||
if count > 0 {
|
|
||||||
log::info!("Cleaned up {} expired entries on startup", count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build expiration queue from existing entries
|
// Build expiration queue from existing entries
|
||||||
let mut exp_queue = ExpirationQueue::new();
|
let mut exp_queue = ExpirationQueue::new();
|
||||||
if let Ok(Some((expires_at, id))) = self.get_next_expiration() {
|
if let Ok(Some((expires_at, id))) = self.get_next_expiration() {
|
||||||
exp_queue.push(expires_at, id);
|
exp_queue.push(expires_at, id);
|
||||||
// Load remaining expirations
|
// Load remaining expirations (exclude already-marked expired entries)
|
||||||
let mut stmt = self
|
let mut stmt = self
|
||||||
.conn
|
.conn
|
||||||
.prepare(
|
.prepare(
|
||||||
"SELECT expires_at, id FROM clipboard WHERE expires_at IS NOT \
|
"SELECT expires_at, id FROM clipboard WHERE expires_at IS NOT \
|
||||||
NULL ORDER BY expires_at ASC",
|
NULL AND (is_expired IS NULL OR is_expired = 0) ORDER BY \
|
||||||
|
expires_at ASC",
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
if let Some(ref mut stmt) = stmt {
|
if let Some(ref mut stmt) = stmt {
|
||||||
|
|
@ -189,11 +183,15 @@ impl WatchCommand for SqliteClipboardDb {
|
||||||
)
|
)
|
||||||
.is_ok();
|
.is_ok();
|
||||||
if exists {
|
if exists {
|
||||||
|
// Mark as expired instead of deleting
|
||||||
self
|
self
|
||||||
.conn
|
.conn
|
||||||
.execute("DELETE FROM clipboard WHERE id = ?1", [id])
|
.execute(
|
||||||
|
"UPDATE clipboard SET is_expired = 1 WHERE id = ?1",
|
||||||
|
[id],
|
||||||
|
)
|
||||||
.ok();
|
.ok();
|
||||||
log::info!("Entry {id} expired and removed");
|
log::info!("Entry {id} marked as expired");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue