improvement: optimize room directory
parent
d35ad69af1
commit
3c3062a316
|
@ -209,17 +209,15 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
.map(|room_id| {
|
||||
let room_id = room_id?;
|
||||
|
||||
// TODO: Do not load full state?
|
||||
let state = db.rooms.room_state_full(&room_id)?;
|
||||
|
||||
let chunk = PublicRoomsChunk {
|
||||
aliases: Vec::new(),
|
||||
canonical_alias: state
|
||||
.get(&(EventType::RoomCanonicalAlias, "".to_owned()))
|
||||
canonical_alias: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomCanonicalAlias, "")?
|
||||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(serde_json::from_value::<
|
||||
Raw<canonical_alias::CanonicalAliasEventContent>,
|
||||
>(s.content.clone())
|
||||
>(s.content)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
|
@ -227,11 +225,12 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
})?
|
||||
.alias)
|
||||
})?,
|
||||
name: state.get(&(EventType::RoomName, "".to_owned())).map_or(
|
||||
Ok::<_, Error>(None),
|
||||
|s| {
|
||||
name: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomName, "")?
|
||||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(serde_json::from_value::<Raw<name::NameEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -240,16 +239,15 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
})?
|
||||
.name()
|
||||
.map(|n| n.to_owned()))
|
||||
},
|
||||
)?,
|
||||
})?,
|
||||
num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(),
|
||||
room_id,
|
||||
topic: state.get(&(EventType::RoomTopic, "".to_owned())).map_or(
|
||||
Ok::<_, Error>(None),
|
||||
|s| {
|
||||
topic: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomTopic, "")?
|
||||
.map_or(Ok::<_, Error>(None), |s| {
|
||||
Ok(Some(
|
||||
serde_json::from_value::<Raw<topic::TopicEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -258,14 +256,14 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
})?
|
||||
.topic,
|
||||
))
|
||||
},
|
||||
)?,
|
||||
world_readable: state
|
||||
.get(&(EventType::RoomHistoryVisibility, "".to_owned()))
|
||||
})?,
|
||||
world_readable: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomHistoryVisibility, "")?
|
||||
.map_or(Ok::<_, Error>(false), |s| {
|
||||
Ok(serde_json::from_value::<
|
||||
Raw<history_visibility::HistoryVisibilityEventContent>,
|
||||
>(s.content.clone())
|
||||
>(s.content)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
|
@ -276,12 +274,13 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
.history_visibility
|
||||
== history_visibility::HistoryVisibility::WorldReadable)
|
||||
})?,
|
||||
guest_can_join: state
|
||||
.get(&(EventType::RoomGuestAccess, "".to_owned()))
|
||||
guest_can_join: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomGuestAccess, "")?
|
||||
.map_or(Ok::<_, Error>(false), |s| {
|
||||
Ok(
|
||||
serde_json::from_value::<Raw<guest_access::GuestAccessEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -292,12 +291,13 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
== guest_access::GuestAccess::CanJoin,
|
||||
)
|
||||
})?,
|
||||
avatar_url: state
|
||||
.get(&(EventType::RoomAvatar, "".to_owned()))
|
||||
avatar_url: db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomAvatar, "")?
|
||||
.map(|s| {
|
||||
Ok::<_, Error>(
|
||||
serde_json::from_value::<Raw<avatar::AvatarEventContent>>(
|
||||
s.content.clone(),
|
||||
s.content,
|
||||
)
|
||||
.expect("from_value::<Raw<..>> can never fail")
|
||||
.deserialize()
|
||||
|
@ -310,6 +310,7 @@ pub async fn get_public_rooms_filtered_helper(
|
|||
.transpose()?
|
||||
// url is now an Option<String> so we must flatten
|
||||
.flatten(),
|
||||
room_id,
|
||||
};
|
||||
Ok(chunk)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue