feat: Remove all uses of roomsynctoken_shortstatehash

This commit is contained in:
Ginger
2026-05-26 14:28:08 -04:00
parent 30c9d6d2df
commit 6a2480774d
5 changed files with 54 additions and 88 deletions
+7
View File
@@ -48,6 +48,13 @@ async fn load_timeline(
ending_count: Option<PduCount>, ending_count: Option<PduCount>,
limit: usize, limit: usize,
) -> Result<TimelinePdus> { ) -> Result<TimelinePdus> {
if let (Some(starting_count), Some(ending_count)) = (starting_count, ending_count) {
debug_assert!(
starting_count <= ending_count,
"starting count {starting_count} > ending count {ending_count}"
);
}
let mut pdu_stream = match starting_count { let mut pdu_stream = match starting_count {
| Some(starting_count) => { | Some(starting_count) => {
let last_timeline_count = services let last_timeline_count = services
+21 -29
View File
@@ -38,6 +38,7 @@ use ruma::{
uint, uint,
}; };
use service::{account_data::AnyRawAccountDataEvent, rooms::short::ShortStateHash}; use service::{account_data::AnyRawAccountDataEvent, rooms::short::ShortStateHash};
use tokio::pin;
use super::{load_timeline, share_encrypted_room}; use super::{load_timeline, share_encrypted_room};
use crate::client::{ use crate::client::{
@@ -344,7 +345,7 @@ struct ShortStateHashes {
#[tracing::instrument(level = "debug", skip_all)] #[tracing::instrument(level = "debug", skip_all)]
async fn fetch_shortstatehashes( async fn fetch_shortstatehashes(
services: &Services, services: &Services,
SyncContext { last_sync_end_count, current_count, .. }: SyncContext<'_>, SyncContext { last_sync_end_count, .. }: SyncContext<'_>,
room_id: &RoomId, room_id: &RoomId,
) -> Result<ShortStateHashes> { ) -> Result<ShortStateHashes> {
// the room state currently. // the room state currently.
@@ -360,20 +361,25 @@ async fn fetch_shortstatehashes(
// this will be None if we are doing an initial sync or if we just joined this // this will be None if we are doing an initial sync or if we just joined this
// room. // room.
let last_sync_end_shortstatehash = let last_sync_end_shortstatehash =
OptionFuture::from(last_sync_end_count.map(|last_sync_end_count| { OptionFuture::from(last_sync_end_count.map(async |last_sync_end_count| {
// look up the shortstatehash saved by the last sync's call to pin! {
// `associate_token_shortstatehash` let pdus_rev = services
services .rooms
.rooms .timeline
.user .pdus_rev(room_id, Some(PduCount::Normal(last_sync_end_count.saturating_sub(1))))
.get_token_shortstatehash(room_id, last_sync_end_count) .ignore_err();
.inspect_err(move |_| { }
debug_warn!(
token = last_sync_end_count, let (_, pdu_at_last_sync_end) = pdus_rev.next().await?;
"Room has no shortstatehash for this token"
); Some(
}) services
.ok() .rooms
.state_accessor
.pdu_shortstatehash(&pdu_at_last_sync_end.event_id)
.await
.expect("pdu should have a shortstatehash"),
)
})) }))
.map(Option::flatten) .map(Option::flatten)
.map(Ok); .map(Ok);
@@ -381,20 +387,6 @@ async fn fetch_shortstatehashes(
let (current_shortstatehash, last_sync_end_shortstatehash) = let (current_shortstatehash, last_sync_end_shortstatehash) =
try_join(current_shortstatehash, last_sync_end_shortstatehash).await?; try_join(current_shortstatehash, last_sync_end_shortstatehash).await?;
/*
associate the `current_count` with the `current_shortstatehash`, so we can
use it on the next sync as the `last_sync_end_shortstatehash`.
TODO: the table written to by this call grows extremely fast, gaining one new entry for each
joined room on _every single sync request_. we need to find a better way to remember the shortstatehash
between syncs.
*/
services
.rooms
.user
.associate_token_shortstatehash(room_id, current_count, current_shortstatehash)
.await;
Ok(ShortStateHashes { Ok(ShortStateHashes {
current_shortstatehash, current_shortstatehash,
last_sync_end_shortstatehash, last_sync_end_shortstatehash,
+23 -7
View File
@@ -15,7 +15,7 @@ use conduwuit::{
BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt, BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt,
future::ReadyEqExt, future::ReadyEqExt,
math::{ruma_from_usize, usize_from_ruma}, math::{ruma_from_usize, usize_from_ruma},
stream::WidebandExt, stream::{TryIgnore, WidebandExt},
}, },
warn, warn,
}; };
@@ -41,6 +41,7 @@ use ruma::{
uint, uint,
}; };
use service::account_data::AnyRawAccountDataEvent; use service::account_data::AnyRawAccountDataEvent;
use tokio::pin;
use super::share_encrypted_room; use super::share_encrypted_room;
use crate::{ use crate::{
@@ -858,12 +859,27 @@ where
continue; continue;
}; };
let since_shortstatehash = services let since_shortstatehash = async {
.rooms pin! {
.user let pdus_rev = services
.get_token_shortstatehash(room_id, globalsince) .rooms
.await .timeline
.ok(); .pdus_rev(room_id, Some(PduCount::Normal(globalsince.saturating_sub(1))))
.ignore_err();
}
let (_, pdu_at_last_sync_end) = pdus_rev.next().await?;
Some(
services
.rooms
.state_accessor
.pdu_shortstatehash(&pdu_at_last_sync_end.event_id)
.await
.expect("pdu should have a shortstatehash"),
)
}
.await;
let encrypted_room = services let encrypted_room = services
.rooms .rooms
+1 -6
View File
@@ -193,12 +193,7 @@ pub(super) static MAPS: &[Descriptor] = &[
}, },
Descriptor { Descriptor {
name: "roomsynctoken_shortstatehash", name: "roomsynctoken_shortstatehash",
file_shape: 3, ..descriptor::DROPPED
val_size_hint: Some(8),
block_size: 512,
compression_level: 3,
bottommost_level: Some(6),
..descriptor::SEQUENTIAL
}, },
Descriptor { Descriptor {
name: "roomuserdataid_accountdata", name: "roomuserdataid_accountdata",
+2 -46
View File
@@ -1,10 +1,10 @@
use std::sync::Arc; use std::sync::Arc;
use conduwuit::{Result, implement}; use conduwuit::{Result, implement};
use database::{Database, Deserialized, Map}; use database::{Deserialized, Map};
use ruma::{RoomId, UserId}; use ruma::{RoomId, UserId};
use crate::{Dep, globals, rooms, rooms::short::ShortStateHash}; use crate::{Dep, globals};
pub struct Service { pub struct Service {
db: Data, db: Data,
@@ -12,32 +12,25 @@ pub struct Service {
} }
struct Data { struct Data {
db: Arc<Database>,
userroomid_notificationcount: Arc<Map>, userroomid_notificationcount: Arc<Map>,
userroomid_highlightcount: Arc<Map>, userroomid_highlightcount: Arc<Map>,
roomuserid_lastnotificationread: Arc<Map>, roomuserid_lastnotificationread: Arc<Map>,
roomsynctoken_shortstatehash: Arc<Map>,
} }
struct Services { struct Services {
globals: Dep<globals::Service>, globals: Dep<globals::Service>,
short: Dep<rooms::short::Service>,
} }
impl crate::Service for Service { impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> { fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { Ok(Arc::new(Self {
db: Data { db: Data {
db: args.db.clone(),
userroomid_notificationcount: args.db["userroomid_notificationcount"].clone(), userroomid_notificationcount: args.db["userroomid_notificationcount"].clone(),
userroomid_highlightcount: args.db["userroomid_highlightcount"].clone(), userroomid_highlightcount: args.db["userroomid_highlightcount"].clone(),
roomuserid_lastnotificationread: args.db["userroomid_highlightcount"].clone(), roomuserid_lastnotificationread: args.db["userroomid_highlightcount"].clone(),
roomsynctoken_shortstatehash: args.db["roomsynctoken_shortstatehash"].clone(),
}, },
services: Services { services: Services {
globals: args.depend::<globals::Service>("globals"), globals: args.depend::<globals::Service>("globals"),
short: args.depend::<rooms::short::Service>("rooms::short"),
}, },
})) }))
} }
@@ -90,40 +83,3 @@ pub async fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -
.deserialized() .deserialized()
.unwrap_or(0) .unwrap_or(0)
} }
#[implement(Service)]
pub async fn associate_token_shortstatehash(
&self,
room_id: &RoomId,
token: u64,
shortstatehash: ShortStateHash,
) {
let shortroomid = self
.services
.short
.get_shortroomid(room_id)
.await
.expect("room exists");
let _cork = self.db.db.cork();
let key: &[u64] = &[shortroomid, token];
self.db
.roomsynctoken_shortstatehash
.put(key, shortstatehash);
}
#[implement(Service)]
pub async fn get_token_shortstatehash(
&self,
room_id: &RoomId,
token: u64,
) -> Result<ShortStateHash> {
let shortroomid = self.services.short.get_shortroomid(room_id).await?;
let key: &[u64] = &[shortroomid, token];
self.db
.roomsynctoken_shortstatehash
.qry(key)
.await
.deserialized()
}