perf: Squash weird mutable variable

This commit is contained in:
timedout authored and Jade Ellis committed 2026-06-27 20:23:23 +01:00
1 parent 22c7fa1b08
commit a1fba2218d
2 files changed
+15 -19

No files matched your search

@@ -26,9 +26,6 @@ impl super::Service {
/// to requesting the full state in PDU format from the remote (`GET
/// /_matrix/federation/v1/state, very slow in large rooms), and persists
/// them directly.
///
/// The end result is a result containing a map of shortstatekeys to event
/// IDs. The underlying `Option` is always `Some`.
#[tracing::instrument(skip_all)]
pub(super) async fn fetch_state(
&self,
@@ -36,7 +33,7 @@ impl super::Service {
create_event: &PduEvent,
room_id: &RoomId,
event_id: &EventId,
) -> Result<Option<HashMap<u64, OwnedEventId>>> {
) -> Result<HashMap<u64, OwnedEventId>> {
let start = Instant::now();
trace!(%origin, "Asking remote for state_ids");
let res: get_room_state_ids::v1::Response = match self
@@ -209,7 +206,7 @@ impl super::Service {
}
}
if state_events.is_empty() {
return Ok(Some(HashMap::new()));
return Ok(HashMap::new());
}
let mut state: HashMap<ShortStateKey, OwnedEventId> =
@@ -242,7 +239,7 @@ impl super::Service {
}
}
trace!(elapsed=?start.elapsed(), "fetch_state finished");
Ok(Some(state))
Ok(state)
}
async fn fetch_state_ids_from_backfill_servers(
@@ -73,25 +73,24 @@ impl super::Service {
event_id = %incoming_pdu.event_id,
"Resolving state at event"
);
let mut state_at_incoming_event = if incoming_pdu.prev_events().count() == 1 {
let state_at_incoming_event = if incoming_pdu.prev_events().count() == 1 {
self.state_at_incoming_degree_one(&incoming_pdu).await?
} else {
self.state_at_incoming_resolved(&incoming_pdu, room_id, &room_version_rules)
.await?
};
let state_at_incoming_event = match state_at_incoming_event {
| Some(s) => s,
| None => {
trace!("Could not calculate incoming state, asking remote {origin} for it");
self.fetch_state(origin, create_event, room_id, incoming_pdu.event_id())
.await
.debug_inspect_err(|e| {
debug_error!("Could not fetch state from {origin}: {e}");
})?
},
};
if state_at_incoming_event.is_none() {
trace!("Could not calculate incoming state, asking remote {origin} for it");
state_at_incoming_event = self
.fetch_state(origin, create_event, room_id, incoming_pdu.event_id())
.await
.debug_inspect_err(|e| {
debug_error!("Could not fetch state from {origin}: {e}");
})?;
}
let state_at_incoming_event =
state_at_incoming_event.expect("we always set this to some above");
if state_at_incoming_event.is_empty()
&& *incoming_pdu.event_type() != StateEventType::RoomCreate.into()
{