Introduce OptionFuture helpers

Optimize user directory searches
This commit is contained in:
dasha_uwu
2026-01-17 05:38:09 +05:00
committed by Jason Volk
parent 95121ad905
commit e78bf21085
28 changed files with 454 additions and 567 deletions

View File

@@ -11,7 +11,7 @@ mod topological_sort;
use std::collections::{BTreeMap, BTreeSet};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::OptionFuture};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt};
use ruma::{OwnedEventId, events::StateEventType, room_version_rules::RoomVersionRules};
pub use self::topological_sort::topological_sort;
@@ -26,7 +26,11 @@ use crate::{
Result, debug,
matrix::{Event, TypeStateKey},
trace,
utils::stream::{BroadbandExt, IterStream},
utils::{
BoolExt,
option::OptionExt,
stream::{BroadbandExt, IterStream},
},
};
/// ConflictMap of OwnedEventId specifically.
@@ -102,10 +106,9 @@ where
|| backport_css;
// Since `org.matrix.hydra.11`, fetch the conflicted state subgraph.
let conflicted_subgraph: OptionFuture<_> = consider_conflicted_subgraph
let conflicted_subgraph = consider_conflicted_subgraph
.then(|| conflicted_states.clone().into_values().flatten())
.map(async |ids| conflicted_subgraph_dfs(ids.stream(), fetch))
.into();
.map_async(async |ids| conflicted_subgraph_dfs(ids.stream(), fetch));
let conflicted_subgraph = conflicted_subgraph
.await
@@ -180,9 +183,8 @@ where
// 3. Take all remaining events that werent picked in step 1 and order them by
// the mainline ordering based on the power level in the partially resolved
// state obtained in step 2.
let sorted_remaining_events: OptionFuture<_> = have_remaining_events
.then(move || mainline_sort(power_event.cloned(), remaining_events, fetch))
.into();
let sorted_remaining_events = have_remaining_events
.then_async(move || mainline_sort(power_event.cloned(), remaining_events, fetch));
let sorted_remaining_events = sorted_remaining_events
.await