From a9d645cbcdff72643c392b004e110bc0f037c803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 21 Jul 2020 16:28:41 +0200 Subject: [PATCH] crypto: Rewrite the device keys fetching in the SQLiteStore using filter_map. --- matrix_sdk_crypto/src/store/sqlite.rs | 28 ++++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index bc382d6b..76aec6ab 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -472,23 +472,19 @@ impl SqliteStore { .fetch_all(&mut *connection) .await?; - let mut keys = BTreeMap::new(); + let keys: BTreeMap = key_rows + .iter() + .filter_map(|row| { + let algorithm: &str = &row.0; + let algorithm = KeyAlgorithm::try_from(algorithm).ok()?; + let key = &row.1; - for row in key_rows { - let algorithm: &str = &row.0; - let algorithm = if let Ok(a) = KeyAlgorithm::try_from(algorithm) { - a - } else { - continue; - }; - - let key = &row.1; - - keys.insert( - AlgorithmAndDeviceId(algorithm, device_id.as_str().into()), - key.to_owned(), - ); - } + Some(( + AlgorithmAndDeviceId(algorithm, device_id.as_str().into()), + key.to_owned(), + )) + }) + .collect(); let device = Device::new( user_id,