|
6 | 6 |
|
7 | 7 | use std::collections::BTreeMap; |
8 | 8 |
|
9 | | -use anyhow::Context as _; |
10 | 9 | use anyhow::Result; |
11 | 10 | use base64::Engine as _; |
12 | 11 | use parking_lot::RwLock; |
@@ -97,25 +96,28 @@ impl SpkiHashStore { |
97 | 96 | pub async fn cleanup(&self, sql: &Sql) -> Result<()> { |
98 | 97 | let now = time(); |
99 | 98 | let removed_hosts = sql |
100 | | - .query_map_vec( |
101 | | - "DELETE FROM tls_spki WHERE ? > timestamp + ? RETURNING host", |
102 | | - (now, 30 * 24 * 60 * 60), |
103 | | - |row| { |
| 99 | + .transaction(|transaction| { |
| 100 | + let mut stmt = transaction |
| 101 | + .prepare("DELETE FROM tls_spki WHERE ? > timestamp + ? RETURNING host")?; |
| 102 | + let mut res = Vec::new(); |
| 103 | + for row in stmt.query_map((now, 30 * 24 * 60 * 60), |row| { |
104 | 104 | let host: String = row.get(0)?; |
105 | 105 | Ok(host) |
106 | | - }, |
107 | | - ) |
108 | | - .await |
109 | | - .context("DELETE FROM tls_spki")?; |
| 106 | + })? { |
| 107 | + res.push(row?); |
| 108 | + } |
110 | 109 |
|
111 | | - // Fix timestamps that happen to be in the future |
112 | | - // if we had clock set incorrectly when the timestamp was stored. |
113 | | - // Otherwise entry may take more than 30 days to expire. |
114 | | - sql.execute( |
115 | | - "UPDATE tls_spki SET timestamp = ?1 WHERE timestamp > ?1", |
116 | | - (now,), |
117 | | - ) |
118 | | - .await?; |
| 110 | + // Fix timestamps that happen to be in the future |
| 111 | + // if we had clock set incorrectly when the timestamp was stored. |
| 112 | + // Otherwise entry may take more than 30 days to expire. |
| 113 | + transaction.execute( |
| 114 | + "UPDATE tls_spki SET timestamp = ?1 WHERE timestamp > ?1", |
| 115 | + (now,), |
| 116 | + )?; |
| 117 | + |
| 118 | + Ok(res) |
| 119 | + }) |
| 120 | + .await?; |
119 | 121 |
|
120 | 122 | let mut lock = self.hash_store.write(); |
121 | 123 | for host in removed_hosts { |
|
0 commit comments