de-arc state_full_ids

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-30 08:09:51 +00:00
parent b5266ad9f5
commit 4a3cc9fffa
9 changed files with 69 additions and 39 deletions

View file

@ -1,4 +1,4 @@
use std::iter::once;
use std::{collections::HashMap, iter::once};
use axum::extract::State;
use conduit::{
@ -10,7 +10,7 @@ use futures::{future::try_join, StreamExt, TryFutureExt};
use ruma::{
api::client::{context::get_context, filter::LazyLoadOptions},
events::StateEventType,
UserId,
OwnedEventId, UserId,
};
use crate::{
@ -124,7 +124,7 @@ pub(crate) async fn get_context_route(
.await
.map_err(|e| err!(Database("State hash not found: {e}")))?;
let state_ids = services
let state_ids: HashMap<_, OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)

View file

@ -32,7 +32,7 @@ use ruma::{
TimelineEventType::*,
},
serde::Raw,
uint, DeviceId, EventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
uint, DeviceId, EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
};
use tracing::{Instrument as _, Span};
@ -398,7 +398,7 @@ async fn handle_left_room(
Err(_) => HashMap::new(),
};
let Ok(left_event_id) = services
let Ok(left_event_id): Result<OwnedEventId> = services
.rooms
.state_accessor
.room_state_get_id(room_id, &StateEventType::RoomMember, sender_user.as_str())
@ -666,7 +666,7 @@ async fn load_joined_room(
let (joined_member_count, invited_member_count, heroes) = calculate_counts().await?;
let current_state_ids = services
let current_state_ids: HashMap<_, OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(current_shortstatehash)
@ -736,7 +736,7 @@ async fn load_joined_room(
let mut delta_state_events = Vec::new();
if since_shortstatehash != current_shortstatehash {
let current_state_ids = services
let current_state_ids: HashMap<_, OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(current_shortstatehash)

View file

@ -1,6 +1,6 @@
use std::{
cmp::{self, Ordering},
collections::{BTreeMap, BTreeSet, HashSet},
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
time::Duration,
};
@ -30,7 +30,7 @@ use ruma::{
TimelineEventType::{self, *},
},
state_res::Event,
uint, MilliSecondsSinceUnixEpoch, OwnedRoomId, UInt, UserId,
uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, UInt, UserId,
};
use service::{rooms::read_receipt::pack_receipts, Services};
@ -211,7 +211,7 @@ pub(crate) async fn sync_events_v4_route(
let new_encrypted_room = encrypted_room && since_encryption.is_err();
if encrypted_room {
let current_state_ids = services
let current_state_ids: HashMap<_, OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(current_shortstatehash)

View file

@ -1,6 +1,6 @@
#![allow(deprecated)]
use std::borrow::Borrow;
use std::{borrow::Borrow, collections::HashMap};
use axum::extract::State;
use conduit::{err, pdu::gen_event_id_canonical_json, utils::IterStream, warn, Error, Result};
@ -11,7 +11,7 @@ use ruma::{
room::member::{MembershipState, RoomMemberEventContent},
StateEventType,
},
CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, ServerName,
CanonicalJsonValue, OwnedEventId, OwnedServerName, OwnedUserId, RoomId, ServerName,
};
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use service::Services;
@ -165,7 +165,7 @@ async fn create_join_event(
drop(mutex_lock);
let state_ids = services
let state_ids: HashMap<_, OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)

View file

@ -3,7 +3,7 @@ use std::{borrow::Borrow, iter::once};
use axum::extract::State;
use conduit::{err, result::LogErr, utils::IterStream, Result};
use futures::{FutureExt, StreamExt, TryStreamExt};
use ruma::api::federation::event::get_room_state;
use ruma::{api::federation::event::get_room_state, OwnedEventId};
use super::AccessCheck;
use crate::Ruma;
@ -30,14 +30,18 @@ pub(crate) async fn get_room_state_route(
.await
.map_err(|_| err!(Request(NotFound("PDU state not found."))))?;
let pdus = services
let state_ids: Vec<OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.await
.log_err()
.map_err(|_| err!(Request(NotFound("PDU state IDs not found."))))?
.values()
.into_values()
.collect();
let pdus = state_ids
.iter()
.try_stream()
.and_then(|id| services.rooms.timeline.get_pdu_json(id))
.and_then(|pdu| {

View file

@ -3,7 +3,7 @@ use std::{borrow::Borrow, iter::once};
use axum::extract::State;
use conduit::{err, Result};
use futures::StreamExt;
use ruma::api::federation::event::get_room_state_ids;
use ruma::{api::federation::event::get_room_state_ids, OwnedEventId};
use super::AccessCheck;
use crate::Ruma;
@ -31,14 +31,13 @@ pub(crate) async fn get_room_state_ids_route(
.await
.map_err(|_| err!(Request(NotFound("Pdu state not found."))))?;
let pdu_ids = services
let pdu_ids: Vec<OwnedEventId> = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.await
.map_err(|_| err!(Request(NotFound("State ids not found"))))?
.into_values()
.map(|id| (*id).to_owned())
.collect();
let auth_chain_ids = services