crypto: More cleanup in the sqlite store.
parent
e4dcca550c
commit
c3654bd03f
|
@ -132,7 +132,7 @@ impl SqliteStore {
|
||||||
let loaded_sessions = self.sessions.get(sender_key).is_some();
|
let loaded_sessions = self.sessions.get(sender_key).is_some();
|
||||||
|
|
||||||
if !loaded_sessions {
|
if !loaded_sessions {
|
||||||
let sessions = self.load_session_for(sender_key).await?;
|
let sessions = self.load_sessions_for(sender_key).await?;
|
||||||
|
|
||||||
if !sessions.is_empty() {
|
if !sessions.is_empty() {
|
||||||
self.sessions.set_for_sender(sender_key, sessions);
|
self.sessions.set_for_sender(sender_key, sessions);
|
||||||
|
@ -142,17 +142,18 @@ impl SqliteStore {
|
||||||
Ok(self.sessions.get(sender_key))
|
Ok(self.sessions.get(sender_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_session_for(&mut self, sender_key: &str) -> Result<Vec<Arc<Mutex<Session>>>> {
|
async fn load_sessions_for(&mut self, sender_key: &str) -> Result<Vec<Arc<Mutex<Session>>>> {
|
||||||
let account_id = self.account_id.ok_or(CryptoStoreError::AccountUnset)?;
|
let account_id = self.account_id.ok_or(CryptoStoreError::AccountUnset)?;
|
||||||
let mut connection = self.connection.lock().await;
|
let mut connection = self.connection.lock().await;
|
||||||
|
|
||||||
let rows: Vec<(String, String, String, String)> = query_as(
|
let rows: Vec<(String, String, String, String)> = query_as(
|
||||||
"SELECT pickle, sender_key, creation_time, last_use_time FROM sessions WHERE account_id = ? and sender_key = ?"
|
"SELECT pickle, sender_key, creation_time, last_use_time
|
||||||
|
FROM sessions WHERE account_id = ? and sender_key = ?",
|
||||||
)
|
)
|
||||||
.bind(account_id)
|
.bind(account_id)
|
||||||
.bind(sender_key)
|
.bind(sender_key)
|
||||||
.fetch_all(&mut *connection)
|
.fetch_all(&mut *connection)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
|
@ -442,7 +443,12 @@ mod test {
|
||||||
|
|
||||||
let sess = session.lock().await;
|
let sess = session.lock().await;
|
||||||
|
|
||||||
let sessions = store.load_sessions().await.expect("Can't load sessions");
|
let sessions = store
|
||||||
assert!(sessions.contains(&sess));
|
.load_sessions_for(&sess.sender_key)
|
||||||
|
.await
|
||||||
|
.expect("Can't load sessions");
|
||||||
|
let loaded_session = &sessions[0];
|
||||||
|
|
||||||
|
assert_eq!(*sess, *loaded_session.lock().await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue