mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-28 05:45:48 +00:00
fed: remove unnecessary mutables, use with_capacity in couple more places
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
68f42f5a2f
commit
f0533e07ef
|
@ -88,15 +88,15 @@ pub(crate) async fn get_server_version_route(
|
|||
// Response type for this endpoint is Json because we need to calculate a
|
||||
// signature for the response
|
||||
pub(crate) async fn get_server_keys_route() -> Result<impl IntoResponse> {
|
||||
let mut verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::new();
|
||||
verify_keys.insert(
|
||||
let verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::from([(
|
||||
format!("ed25519:{}", services().globals.keypair().version())
|
||||
.try_into()
|
||||
.expect("found invalid server signing keys in DB"),
|
||||
VerifyKey {
|
||||
key: Base64::new(services().globals.keypair().public_key().to_vec()),
|
||||
},
|
||||
);
|
||||
)]);
|
||||
|
||||
let mut response = serde_json::from_slice(
|
||||
get_server_keys::v2::Response {
|
||||
server_key: Raw::new(&ServerSigningKeys {
|
||||
|
@ -375,14 +375,11 @@ pub(crate) async fn send_transaction_message_route(
|
|||
.any(|member| member.server_name() == user_id.server_name())
|
||||
{
|
||||
for event_id in &user_updates.event_ids {
|
||||
let mut user_receipts = BTreeMap::new();
|
||||
user_receipts.insert(user_id.clone(), user_updates.data.clone());
|
||||
let user_receipts = BTreeMap::from([(user_id.clone(), user_updates.data.clone())]);
|
||||
|
||||
let mut receipts = BTreeMap::new();
|
||||
receipts.insert(ReceiptType::Read, user_receipts);
|
||||
let receipts = BTreeMap::from([(ReceiptType::Read, user_receipts)]);
|
||||
|
||||
let mut receipt_content = BTreeMap::new();
|
||||
receipt_content.insert(event_id.to_owned(), receipts);
|
||||
let receipt_content = BTreeMap::from([(event_id.to_owned(), receipts)]);
|
||||
|
||||
let event = ReceiptEvent {
|
||||
content: ReceiptEventContent(receipt_content),
|
||||
|
@ -633,13 +630,17 @@ pub(crate) async fn get_backfill_route(body: Ruma<get_backfill::v1::Request>) ->
|
|||
.max()
|
||||
.ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "Event not found."))?;
|
||||
|
||||
let limit = body.limit.min(uint!(100));
|
||||
let limit = body
|
||||
.limit
|
||||
.min(uint!(100))
|
||||
.try_into()
|
||||
.expect("UInt could not be converted to usize");
|
||||
|
||||
let all_events = services()
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_until(user_id!("@doesntmatter:conduit.rs"), &body.room_id, until)?
|
||||
.take(limit.try_into().unwrap());
|
||||
.take(limit);
|
||||
|
||||
let events = all_events
|
||||
.filter_map(Result::ok)
|
||||
|
@ -685,11 +686,17 @@ pub(crate) async fn get_missing_events_route(
|
|||
.event_handler
|
||||
.acl_check(origin, &body.room_id)?;
|
||||
|
||||
let mut queued_events = body.latest_events.clone();
|
||||
let mut events = Vec::new();
|
||||
let limit = body
|
||||
.limit
|
||||
.try_into()
|
||||
.expect("UInt could not be converted to usize");
|
||||
|
||||
let mut i = 0;
|
||||
while i < queued_events.len() && events.len() < u64::from(body.limit) as usize {
|
||||
let mut queued_events = body.latest_events.clone();
|
||||
// the vec will never have more entries the limit
|
||||
let mut events = Vec::with_capacity(limit);
|
||||
|
||||
let mut i: usize = 0;
|
||||
while i < queued_events.len() && events.len() < limit {
|
||||
if let Some(pdu) = services().rooms.timeline.get_pdu_json(&queued_events[i])? {
|
||||
let room_id_str = pdu
|
||||
.get("room_id")
|
||||
|
|
Loading…
Reference in a new issue