mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Reduce database lookups in some cases
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use conduwuit::{Event, PduEvent, Result, err};
|
use conduwuit::{Event, PduEvent, Result, err};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
EventId, RoomId, UserId,
|
UserId,
|
||||||
api::Direction,
|
api::Direction,
|
||||||
events::relation::{BundledMessageLikeRelations, BundledReference, ReferenceChunk},
|
events::relation::{BundledMessageLikeRelations, BundledReference, ReferenceChunk},
|
||||||
};
|
};
|
||||||
@@ -19,14 +19,18 @@ impl super::Service {
|
|||||||
pub async fn get_bundled_aggregations(
|
pub async fn get_bundled_aggregations(
|
||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
room_id: &RoomId,
|
pdu: &PduEvent,
|
||||||
event_id: &EventId,
|
|
||||||
) -> Result<Option<BundledMessageLikeRelations<Box<serde_json::value::RawValue>>>> {
|
) -> Result<Option<BundledMessageLikeRelations<Box<serde_json::value::RawValue>>>> {
|
||||||
|
// Events that can never get bundled aggregations
|
||||||
|
if pdu.state_key().is_some() || Self::is_replacement_event(pdu) {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
let relations = self
|
let relations = self
|
||||||
.get_relations(
|
.get_relations(
|
||||||
user_id,
|
user_id,
|
||||||
room_id,
|
&pdu.room_id_or_hash(),
|
||||||
event_id,
|
pdu.event_id(),
|
||||||
conduwuit::PduCount::max(),
|
conduwuit::PduCount::max(),
|
||||||
MAX_BUNDLED_RELATIONS,
|
MAX_BUNDLED_RELATIONS,
|
||||||
0,
|
0,
|
||||||
@@ -80,10 +84,8 @@ impl super::Service {
|
|||||||
// Handle m.replace relations - find the most recent valid one (lazy load
|
// Handle m.replace relations - find the most recent valid one (lazy load
|
||||||
// original event)
|
// original event)
|
||||||
if !replace_events.is_empty() {
|
if !replace_events.is_empty() {
|
||||||
let original_event = self.services.timeline.get_pdu(event_id).await?;
|
|
||||||
|
|
||||||
if let Some(replacement) =
|
if let Some(replacement) =
|
||||||
Self::find_most_recent_valid_replacement(&original_event, &replace_events).await?
|
Self::find_most_recent_valid_replacement(pdu, &replace_events).await?
|
||||||
{
|
{
|
||||||
bundled.replace = Some(Self::serialize_replacement(replacement)?);
|
bundled.replace = Some(Self::serialize_replacement(replacement)?);
|
||||||
}
|
}
|
||||||
@@ -161,9 +163,7 @@ impl super::Service {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let bundled_aggregations = self
|
let bundled_aggregations = self.get_bundled_aggregations(user_id, pdu).await?;
|
||||||
.get_bundled_aggregations(user_id, &pdu.room_id_or_hash(), pdu.event_id())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if let Some(aggregations) = bundled_aggregations {
|
if let Some(aggregations) = bundled_aggregations {
|
||||||
let aggregations_json = serde_json::to_value(aggregations)
|
let aggregations_json = serde_json::to_value(aggregations)
|
||||||
|
|||||||
Reference in New Issue
Block a user