mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
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:
@@ -70,7 +70,9 @@ impl LinkCache {
|
|||||||
pub async fn get(&self, key: &str, ttl: Duration) -> Option<CachedPost> {
|
pub async fn get(&self, key: &str, ttl: Duration) -> Option<CachedPost> {
|
||||||
let key = key.to_string();
|
let key = key.to_string();
|
||||||
let ttl = ttl.as_secs_f64();
|
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 =
|
let mut stmt =
|
||||||
conn.prepare("SELECT payload, created_at FROM link_cache WHERE url = ?1")?;
|
conn.prepare("SELECT payload, created_at FROM link_cache WHERE url = ?1")?;
|
||||||
let mut rows = stmt.query(params![key])?;
|
let mut rows = stmt.query(params![key])?;
|
||||||
@@ -100,7 +102,9 @@ impl LinkCache {
|
|||||||
pub async fn put(&self, key: &str, post: &CachedPost) {
|
pub async fn put(&self, key: &str, post: &CachedPost) {
|
||||||
let key = key.to_string();
|
let key = key.to_string();
|
||||||
let payload = serde_json::to_string(post).expect("cached post serializes");
|
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(
|
conn.execute(
|
||||||
"INSERT OR REPLACE INTO link_cache (url, payload, created_at) VALUES (?1, ?2, ?3)",
|
"INSERT OR REPLACE INTO link_cache (url, payload, created_at) VALUES (?1, ?2, ?3)",
|
||||||
params![key, payload, now_f64()],
|
params![key, payload, now_f64()],
|
||||||
@@ -116,7 +120,9 @@ impl LinkCache {
|
|||||||
/// Drops an entry (e.g. a cached file id that turned out invalid).
|
/// Drops an entry (e.g. a cached file id that turned out invalid).
|
||||||
pub async fn remove(&self, key: &str) {
|
pub async fn remove(&self, key: &str) {
|
||||||
let key = key.to_string();
|
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])?;
|
conn.execute("DELETE FROM link_cache WHERE url = ?1", params![key])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -129,7 +135,9 @@ impl LinkCache {
|
|||||||
/// Removes expired entries; returns how many were deleted.
|
/// Removes expired entries; returns how many were deleted.
|
||||||
pub async fn prune(&self, ttl: Duration) -> usize {
|
pub async fn prune(&self, ttl: Duration) -> usize {
|
||||||
let cutoff = now_f64() - ttl.as_secs_f64();
|
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(
|
conn.execute(
|
||||||
"DELETE FROM link_cache WHERE created_at < ?1",
|
"DELETE FROM link_cache WHERE created_at < ?1",
|
||||||
params![cutoff],
|
params![cutoff],
|
||||||
@@ -149,7 +157,9 @@ impl LinkCache {
|
|||||||
/// `key` is `None`. Returns how many rows were removed.
|
/// `key` is `None`. Returns how many rows were removed.
|
||||||
pub async fn clear(&self, key: Option<&str>) -> usize {
|
pub async fn clear(&self, key: Option<&str>) -> usize {
|
||||||
let key = key.map(str::to_string);
|
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]),
|
Some(key) => conn.execute("DELETE FROM link_cache WHERE url = ?1", params![key]),
|
||||||
None => conn.execute("DELETE FROM link_cache", []),
|
None => conn.execute("DELETE FROM link_cache", []),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -160,8 +160,7 @@ impl PersistentTaskQueue {
|
|||||||
if sweep_stop.load(Ordering::Relaxed) {
|
if sweep_stop.load(Ordering::Relaxed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let result =
|
let result = sweep_pool.with_conn(move |conn| recover_update(conn)).await;
|
||||||
sweep_pool.with_conn(move |conn| recover_update(conn)).await;
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
log::error!("queue sweep failed: {e}");
|
log::error!("queue sweep failed: {e}");
|
||||||
}
|
}
|
||||||
@@ -309,7 +308,9 @@ impl QueueWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn earliest_run_after(&self) -> Option<f64> {
|
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 =
|
let mut stmt =
|
||||||
conn.prepare("SELECT MIN(run_after) FROM tasks WHERE status='pending'")?;
|
conn.prepare("SELECT MIN(run_after) FROM tasks WHERE status='pending'")?;
|
||||||
let mut rows = stmt.query([])?;
|
let mut rows = stmt.query([])?;
|
||||||
@@ -374,7 +375,9 @@ impl QueueWorker {
|
|||||||
|
|
||||||
async fn delete_row(&self, id: &str) {
|
async fn delete_row(&self, id: &str) {
|
||||||
let id = id.to_string();
|
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])?;
|
conn.execute("DELETE FROM tasks WHERE id = ?1", params![id])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ impl ChatStore {
|
|||||||
return data.clone();
|
return data.clone();
|
||||||
}
|
}
|
||||||
let chat_key = chat_id.to_string();
|
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
|
// Concurrent handler tasks (batch-forwards) may write chat_state
|
||||||
// while this read runs; the shared busy timeout handles the
|
// while this read runs; the shared busy timeout handles the
|
||||||
// write-lock collision instead of failing the query.
|
// write-lock collision instead of failing the query.
|
||||||
@@ -103,7 +105,9 @@ impl ChatStore {
|
|||||||
self.cache.lock().insert(chat_id, data.clone());
|
self.cache.lock().insert(chat_id, data.clone());
|
||||||
let payload = serde_json::to_string(data).expect("chat state serializes");
|
let payload = serde_json::to_string(data).expect("chat state serializes");
|
||||||
let chat_id = chat_id.to_string();
|
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(
|
conn.execute(
|
||||||
"INSERT OR REPLACE INTO chat_state (chat_id, payload) VALUES (?1, ?2)",
|
"INSERT OR REPLACE INTO chat_state (chat_id, payload) VALUES (?1, ?2)",
|
||||||
params![chat_id, payload],
|
params![chat_id, payload],
|
||||||
|
|||||||
Reference in New Issue
Block a user