This commit is contained in:
2026-05-21 09:39:12 +02:00
parent fc085a8a83
commit 041e90a8f2
15 changed files with 269 additions and 207 deletions

View File

@ -101,9 +101,7 @@ impl Database {
ExtendedColorType::Rgb8,
)?;
}
None => {
return Ok(());
}
None => return Ok(()),
}
("image", format!("{}.jpg", img.id))
}
@ -115,7 +113,6 @@ impl Database {
)?;
self.trim_to_max()?;
Ok(())
}
@ -124,8 +121,10 @@ impl Database {
return Ok(());
}
let tx = self.conn.unchecked_transaction()?;
let image_files: Vec<String> = {
let mut stmt = self.conn.prepare(
let mut stmt = tx.prepare(
"SELECT content FROM history
WHERE type = 'image'
AND id NOT IN (
@ -137,13 +136,15 @@ impl Database {
.collect()
};
self.conn.execute(
tx.execute(
"DELETE FROM history WHERE id NOT IN (
SELECT id FROM history ORDER BY timestamp DESC LIMIT ?1
)",
[self.max_entries as i64],
)?;
tx.commit()?;
for filename in image_files {
let path = Path::new(&self.dir_path).join("images").join(&filename);
if path.exists() {
@ -213,18 +214,19 @@ impl Database {
let cutoff_ms = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as i64
- (days as i64 * 86_400_000);
let tx = self.conn.unchecked_transaction()?;
let image_files: Vec<String> = {
let mut stmt = self
.conn
.prepare("SELECT content FROM history WHERE type = 'image' AND timestamp < ?1")?;
let mut stmt =
tx.prepare("SELECT content FROM history WHERE type = 'image' AND timestamp < ?1")?;
stmt.query_map([cutoff_ms], |row| row.get(0))?
.filter_map(|r| r.ok())
.collect()
};
let count = self
.conn
.execute("DELETE FROM history WHERE timestamp < ?1", [cutoff_ms])?;
let count = tx.execute("DELETE FROM history WHERE timestamp < ?1", [cutoff_ms])?;
tx.commit()?;
for filename in image_files {
let path = Path::new(&self.dir_path).join("images").join(&filename);