style: rustfmt the DbPool call sites from the connection-pool change

Formatting-only; the pool commit landed before cargo fmt was run.
This commit is contained in:
2026-08-13 22:25:13 +08:00
parent 1747d321d8
commit 2e2d1b3506
3 changed files with 99 additions and 82 deletions
+15 -5
View File
@@ -70,7 +70,9 @@ impl LinkCache {
pub async fn get(&self, key: &str, ttl: Duration) -> Option<CachedPost> {
let key = key.to_string();
let ttl = ttl.as_secs_f64();
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
let mut stmt =
conn.prepare("SELECT payload, created_at FROM link_cache WHERE url = ?1")?;
let mut rows = stmt.query(params![key])?;
@@ -100,7 +102,9 @@ impl LinkCache {
pub async fn put(&self, key: &str, post: &CachedPost) {
let key = key.to_string();
let payload = serde_json::to_string(post).expect("cached post serializes");
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
conn.execute(
"INSERT OR REPLACE INTO link_cache (url, payload, created_at) VALUES (?1, ?2, ?3)",
params![key, payload, now_f64()],
@@ -116,7 +120,9 @@ impl LinkCache {
/// Drops an entry (e.g. a cached file id that turned out invalid).
pub async fn remove(&self, key: &str) {
let key = key.to_string();
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
conn.execute("DELETE FROM link_cache WHERE url = ?1", params![key])?;
Ok(())
})
@@ -129,7 +135,9 @@ impl LinkCache {
/// Removes expired entries; returns how many were deleted.
pub async fn prune(&self, ttl: Duration) -> usize {
let cutoff = now_f64() - ttl.as_secs_f64();
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
conn.execute(
"DELETE FROM link_cache WHERE created_at < ?1",
params![cutoff],
@@ -149,7 +157,9 @@ impl LinkCache {
/// `key` is `None`. Returns how many rows were removed.
pub async fn clear(&self, key: Option<&str>) -> usize {
let key = key.map(str::to_string);
let result = self.pool.with_conn(move |conn| match &key {
let result = self
.pool
.with_conn(move |conn| match &key {
Some(key) => conn.execute("DELETE FROM link_cache WHERE url = ?1", params![key]),
None => conn.execute("DELETE FROM link_cache", []),
})
+7 -4
View File
@@ -160,8 +160,7 @@ impl PersistentTaskQueue {
if sweep_stop.load(Ordering::Relaxed) {
break;
}
let result =
sweep_pool.with_conn(move |conn| recover_update(conn)).await;
let result = sweep_pool.with_conn(move |conn| recover_update(conn)).await;
if let Err(e) = result {
log::error!("queue sweep failed: {e}");
}
@@ -309,7 +308,9 @@ impl QueueWorker {
}
async fn earliest_run_after(&self) -> Option<f64> {
let result = self.pool.with_conn(|conn| {
let result = self
.pool
.with_conn(|conn| {
let mut stmt =
conn.prepare("SELECT MIN(run_after) FROM tasks WHERE status='pending'")?;
let mut rows = stmt.query([])?;
@@ -374,7 +375,9 @@ impl QueueWorker {
async fn delete_row(&self, id: &str) {
let id = id.to_string();
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
conn.execute("DELETE FROM tasks WHERE id = ?1", params![id])?;
Ok(())
})
+6 -2
View File
@@ -76,7 +76,9 @@ impl ChatStore {
return data.clone();
}
let chat_key = chat_id.to_string();
let payload = self.pool.with_conn(move |conn| {
let payload = self
.pool
.with_conn(move |conn| {
// Concurrent handler tasks (batch-forwards) may write chat_state
// while this read runs; the shared busy timeout handles the
// write-lock collision instead of failing the query.
@@ -103,7 +105,9 @@ impl ChatStore {
self.cache.lock().insert(chat_id, data.clone());
let payload = serde_json::to_string(data).expect("chat state serializes");
let chat_id = chat_id.to_string();
let result = self.pool.with_conn(move |conn| {
let result = self
.pool
.with_conn(move |conn| {
conn.execute(
"INSERT OR REPLACE INTO chat_state (chat_id, payload) VALUES (?1, ?2)",
params![chat_id, payload],