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
|
// Response type for this endpoint is Json because we need to calculate a
|
||||||
// signature for the response
|
// signature for the response
|
||||||
pub(crate) async fn get_server_keys_route() -> Result<impl IntoResponse> {
|
pub(crate) async fn get_server_keys_route() -> Result<impl IntoResponse> {
|
||||||
let mut verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::new();
|
let verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::from([(
|
||||||
verify_keys.insert(
|
|
||||||
format!("ed25519:{}", services().globals.keypair().version())
|
format!("ed25519:{}", services().globals.keypair().version())
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("found invalid server signing keys in DB"),
|
.expect("found invalid server signing keys in DB"),
|
||||||
VerifyKey {
|
VerifyKey {
|
||||||
key: Base64::new(services().globals.keypair().public_key().to_vec()),
|
key: Base64::new(services().globals.keypair().public_key().to_vec()),
|
||||||
},
|
},
|
||||||
);
|
)]);
|
||||||
|
|
||||||
let mut response = serde_json::from_slice(
|
let mut response = serde_json::from_slice(
|
||||||
get_server_keys::v2::Response {
|
get_server_keys::v2::Response {
|
||||||
server_key: Raw::new(&ServerSigningKeys {
|
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())
|
.any(|member| member.server_name() == user_id.server_name())
|
||||||
{
|
{
|
||||||
for event_id in &user_updates.event_ids {
|
for event_id in &user_updates.event_ids {
|
||||||
let mut user_receipts = BTreeMap::new();
|
let user_receipts = BTreeMap::from([(user_id.clone(), user_updates.data.clone())]);
|
||||||
user_receipts.insert(user_id.clone(), user_updates.data.clone());
|
|
||||||
|
|
||||||
let mut receipts = BTreeMap::new();
|
let receipts = BTreeMap::from([(ReceiptType::Read, user_receipts)]);
|
||||||
receipts.insert(ReceiptType::Read, user_receipts);
|
|
||||||
|
|
||||||
let mut receipt_content = BTreeMap::new();
|
let receipt_content = BTreeMap::from([(event_id.to_owned(), receipts)]);
|
||||||
receipt_content.insert(event_id.to_owned(), receipts);
|
|
||||||
|
|
||||||
let event = ReceiptEvent {
|
let event = ReceiptEvent {
|
||||||
content: ReceiptEventContent(receipt_content),
|
content: ReceiptEventContent(receipt_content),
|
||||||
|
@ -633,13 +630,17 @@ pub(crate) async fn get_backfill_route(body: Ruma<get_backfill::v1::Request>) ->
|
||||||
.max()
|
.max()
|
||||||
.ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "Event not found."))?;
|
.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()
|
let all_events = services()
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.pdus_until(user_id!("@doesntmatter:conduit.rs"), &body.room_id, until)?
|
.pdus_until(user_id!("@doesntmatter:conduit.rs"), &body.room_id, until)?
|
||||||
.take(limit.try_into().unwrap());
|
.take(limit);
|
||||||
|
|
||||||
let events = all_events
|
let events = all_events
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
|
@ -685,11 +686,17 @@ pub(crate) async fn get_missing_events_route(
|
||||||
.event_handler
|
.event_handler
|
||||||
.acl_check(origin, &body.room_id)?;
|
.acl_check(origin, &body.room_id)?;
|
||||||
|
|
||||||
let mut queued_events = body.latest_events.clone();
|
let limit = body
|
||||||
let mut events = Vec::new();
|
.limit
|
||||||
|
.try_into()
|
||||||
|
.expect("UInt could not be converted to usize");
|
||||||
|
|
||||||
let mut i = 0;
|
let mut queued_events = body.latest_events.clone();
|
||||||
while i < queued_events.len() && events.len() < u64::from(body.limit) as usize {
|
// 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])? {
|
if let Some(pdu) = services().rooms.timeline.get_pdu_json(&queued_events[i])? {
|
||||||
let room_id_str = pdu
|
let room_id_str = pdu
|
||||||
.get("room_id")
|
.get("room_id")
|
||||||
|
|
Loading…
Reference in a new issue