Introduce OptionFuture helpers
Optimize user directory searches
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use axum::extract::State;
|
||||
use futures::{FutureExt, future::OptionFuture};
|
||||
use futures::FutureExt;
|
||||
use ruma::{
|
||||
CanonicalJsonObject, EventEncryptionAlgorithm, Int, OwnedRoomAliasId, OwnedRoomId,
|
||||
OwnedUserId, RoomId, RoomVersionId,
|
||||
@@ -32,7 +32,7 @@ use serde_json::{json, value::to_raw_value};
|
||||
use tuwunel_core::{
|
||||
Err, Result, debug_info, debug_warn, err, info,
|
||||
matrix::{StateKey, pdu::PduBuilder, room_version},
|
||||
utils::BoolExt,
|
||||
utils::{BoolExt, option::OptionExt},
|
||||
warn,
|
||||
};
|
||||
use tuwunel_service::{Services, appservice::RegistrationInfo, rooms::state::RoomMutexGuard};
|
||||
@@ -72,11 +72,10 @@ pub(crate) async fn create_room_route(
|
||||
| _ => RoomPreset::PrivateChat, // Room visibility should not be custom
|
||||
});
|
||||
|
||||
let alias: OptionFuture<_> = body
|
||||
let alias = body
|
||||
.room_alias_name
|
||||
.as_ref()
|
||||
.map(|alias| room_alias_check(&services, alias, body.appservice_info.as_ref()))
|
||||
.into();
|
||||
.map_async(|alias| room_alias_check(&services, alias, body.appservice_info.as_ref()));
|
||||
|
||||
// Determine room version
|
||||
let (room_version, version_rules) = body
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
use axum::extract::State;
|
||||
use axum_client_ip::InsecureClientIp;
|
||||
use futures::{
|
||||
FutureExt, StreamExt, TryFutureExt,
|
||||
future::{OptionFuture, join3},
|
||||
stream::FuturesUnordered,
|
||||
};
|
||||
use futures::{FutureExt, StreamExt, TryFutureExt, future::join3, stream::FuturesUnordered};
|
||||
use ruma::{
|
||||
OwnedServerName, RoomId, UserId,
|
||||
api::{
|
||||
@@ -16,7 +12,7 @@ use ruma::{
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Err, Result, debug_warn, trace,
|
||||
utils::{IterStream, future::TryExtExt},
|
||||
utils::{IterStream, future::TryExtExt, option::OptionExt},
|
||||
};
|
||||
use tuwunel_service::Services;
|
||||
|
||||
@@ -158,14 +154,12 @@ async fn local_room_summary_response(
|
||||
.room_joined_count(room_id)
|
||||
.unwrap_or(0);
|
||||
|
||||
let membership: OptionFuture<_> = sender_user
|
||||
.map(|sender_user| {
|
||||
services
|
||||
.state_accessor
|
||||
.get_member(room_id, sender_user)
|
||||
.map_ok_or(MembershipState::Leave, |content| content.membership)
|
||||
})
|
||||
.into();
|
||||
let membership = sender_user.map_async(|sender_user| {
|
||||
services
|
||||
.state_accessor
|
||||
.get_member(room_id, sender_user)
|
||||
.map_ok_or(MembershipState::Leave, |content| content.membership)
|
||||
});
|
||||
|
||||
let (
|
||||
canonical_alias,
|
||||
|
||||
Reference in New Issue
Block a user