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