diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index dfef34d..be5501a 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -160,15 +160,12 @@ pub async fn get_public_rooms_filtered_helper( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c) + .expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch, diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 7bb019e..f19d4b9 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -2023,39 +2023,33 @@ impl Rooms { .map(str::to_lowercase) .collect::>(); - let iterators = words - .clone() - .into_iter() - .map(move |word| { - let mut prefix2 = prefix.clone(); - prefix2.extend_from_slice(word.as_bytes()); - prefix2.push(0xff); + let iterators = words.clone().into_iter().map(move |word| { + let mut prefix2 = prefix.clone(); + prefix2.extend_from_slice(word.as_bytes()); + prefix2.push(0xff); - let mut last_possible_id = prefix2.clone(); - last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes()); + let mut last_possible_id = prefix2.clone(); + last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes()); - Ok::<_, Error>( - self.tokenids - .iter_from(&last_possible_id, true) // Newest pdus first - .take_while(move |(k, _)| k.starts_with(&prefix2)) - .map(|(key, _)| { - let pduid_index = key - .iter() - .enumerate() - .filter(|(_, &b)| b == 0xff) - .nth(1) - .ok_or_else(|| Error::bad_database("Invalid tokenid in db."))? - .0 - + 1; // +1 because the pdu id starts AFTER the separator + self.tokenids + .iter_from(&last_possible_id, true) // Newest pdus first + .take_while(move |(k, _)| k.starts_with(&prefix2)) + .map(|(key, _)| { + let pduid_index = key + .iter() + .enumerate() + .filter(|(_, &b)| b == 0xff) + .nth(1) + .ok_or_else(|| Error::bad_database("Invalid tokenid in db."))? + .0 + + 1; // +1 because the pdu id starts AFTER the separator - let pdu_id = key[pduid_index..].to_vec(); + let pdu_id = key[pduid_index..].to_vec(); - Ok::<_, Error>(pdu_id) - }) - .filter_map(|r| r.ok()), - ) - }) - .filter_map(|r| r.ok()); + Ok::<_, Error>(pdu_id) + }) + .filter_map(|r| r.ok()) + }); Ok(( utils::common_elements(iterators, |a, b| { diff --git a/src/server_server.rs b/src/server_server.rs index 6d074ec..961cc9d 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -532,15 +532,11 @@ pub async fn get_public_rooms_filtered_route( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c).expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch, @@ -580,15 +576,11 @@ pub async fn get_public_rooms_route( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c).expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch,