fix(sync/v3): Cleanup part 1: mostly fix redundant data in state

This commit is contained in:
Ginger
2025-12-07 19:58:24 +00:00
parent 502919b248
commit 2940bc69c1
13 changed files with 466 additions and 426 deletions
+4 -2
View File
@@ -129,13 +129,15 @@ pub fn changes_since<'a>(
&'a self,
room_id: Option<&'a RoomId>,
user_id: &'a UserId,
since: u64,
since: Option<u64>,
to: Option<u64>,
) -> impl Stream<Item = AnyRawAccountDataEvent> + Send + 'a {
type Key<'a> = (Option<&'a RoomId>, &'a UserId, u64, Ignore);
// Skip the data that's exactly at since, because we sent that last time
let first_possible = (room_id, user_id, since.saturating_add(1));
// ...unless this is an initial sync, in which case send everything
let first_possible =
(room_id, user_id, since.map(|since| since.saturating_add(1)).unwrap_or(0));
self.db
.roomuserdataid_accountdata
+4 -4
View File
@@ -104,16 +104,16 @@ impl Service {
Ok(Raw::from_json(event))
}
/// Returns an iterator over the most recent read_receipts in a room that
/// happened after the event with id `since`.
/// Returns an iterator over the most recent read_receipts in a room,
/// optionally after the event with id `since`.
#[inline]
#[tracing::instrument(skip(self), level = "debug")]
pub fn readreceipts_since<'a>(
&'a self,
room_id: &'a RoomId,
since: u64,
since: Option<u64>,
) -> impl Stream<Item = ReceiptItem<'a>> + Send + 'a {
self.db.readreceipts_since(room_id, since)
self.db.readreceipts_since(room_id, since.unwrap_or(0))
}
/// Sets a private read marker at PDU `count`.
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{borrow::Borrow, ops::Deref, sync::Arc};
use conduwuit::{
Result, at, err, implement,
Pdu, Result, at, err, implement,
matrix::{Event, StateKey},
pair_of,
utils::{
@@ -125,7 +125,7 @@ pub async fn state_get(
shortstatehash: ShortStateHash,
event_type: &StateEventType,
state_key: &str,
) -> Result<impl Event> {
) -> Result<Pdu> {
self.state_get_id(shortstatehash, event_type, state_key)
.and_then(async |event_id: OwnedEventId| self.services.timeline.get_pdu(&event_id).await)
.await
+2 -2
View File
@@ -423,7 +423,7 @@ impl Service {
let keys_changed = self
.services
.users
.room_keys_changed(room_id, since.0, None)
.room_keys_changed(room_id, Some(since.0), None)
.ready_filter(|(user_id, _)| self.services.globals.user_is_local(user_id));
pin_mut!(keys_changed);
@@ -520,7 +520,7 @@ impl Service {
let receipts = self
.services
.read_receipt
.readreceipts_since(room_id, since.0);
.readreceipts_since(room_id, Some(since.0));
pin_mut!(receipts);
let mut read = BTreeMap::<OwnedUserId, ReceiptData>::new();
+4 -3
View File
@@ -790,7 +790,7 @@ impl Service {
pub fn keys_changed<'a>(
&'a self,
user_id: &'a UserId,
from: u64,
from: Option<u64>,
to: Option<u64>,
) -> impl Stream<Item = &'a UserId> + Send + 'a {
self.keys_changed_user_or_room(user_id.as_str(), from, to)
@@ -801,7 +801,7 @@ impl Service {
pub fn room_keys_changed<'a>(
&'a self,
room_id: &'a RoomId,
from: u64,
from: Option<u64>,
to: Option<u64>,
) -> impl Stream<Item = (&'a UserId, u64)> + Send + 'a {
self.keys_changed_user_or_room(room_id.as_str(), from, to)
@@ -810,11 +810,12 @@ impl Service {
fn keys_changed_user_or_room<'a>(
&'a self,
user_or_room_id: &'a str,
from: u64,
from: Option<u64>,
to: Option<u64>,
) -> impl Stream<Item = (&'a UserId, u64)> + Send + 'a {
type KeyVal<'a> = ((&'a str, u64), &'a UserId);
let from = from.unwrap_or(0);
let to = to.unwrap_or(u64::MAX);
let start = (user_or_room_id, from.saturating_add(1));
self.db