Add query to get latest account data count.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-10 06:45:33 +00:00
parent 4918868632
commit ab8536d5c3

View File

@@ -14,10 +14,10 @@ use ruma::{
};
use serde::Deserialize;
use tuwunel_core::{
Err, Result, err, implement,
Err, Result, at, err, implement,
utils::{ReadyExt, result::LogErr, stream::TryIgnore},
};
use tuwunel_database::{Deserialized, Handle, Ignore, Json, Map};
use tuwunel_database::{Deserialized, Handle, Ignore, Interfix, Json, Map};
pub struct Service {
services: Arc<crate::services::OnceServices>,
@@ -162,3 +162,27 @@ pub fn changes_since<'a>(
})
.ignore_err()
}
/// Returns all changes to the account data that happened after `since`.
#[implement(Service)]
pub async fn last_count<'a>(
&'a self,
room_id: Option<&'a RoomId>,
user_id: &'a UserId,
upper: u64,
) -> Result<u64> {
type Key<'a> = (Option<&'a RoomId>, &'a UserId, u64, Ignore);
let key = (room_id, user_id, upper, Interfix);
self.db
.roomuserdataid_accountdata
.rev_keys_from(&key)
.ignore_err()
.ready_take_while(move |(room_id_, user_id_, ..): &Key<'_>| {
room_id == *room_id_ && user_id == *user_id_
})
.map(at!(2))
.next()
.await
.ok_or_else(|| err!(Request(NotFound("No account data found."))))
}