From 4b9b85f671b3ad1e516472ee0d4a94ec8b743757 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 2 Aug 2025 03:36:42 +0000 Subject: [PATCH] ABI encapsulations; generate leaf code in pub fn's rather than inling them. Signed-off-by: Jason Volk --- src/admin/query/globals.rs | 2 +- src/service/globals/data.rs | 12 +++++++----- src/service/globals/mod.rs | 7 +------ src/service/presence/data.rs | 2 ++ src/service/presence/mod.rs | 1 - src/service/rooms/pdu_metadata/data.rs | 4 ++++ src/service/rooms/pdu_metadata/mod.rs | 3 --- src/service/rooms/read_receipt/data.rs | 5 +++++ src/service/rooms/read_receipt/mod.rs | 8 +++----- src/service/sending/data.rs | 1 + 10 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/admin/query/globals.rs b/src/admin/query/globals.rs index 2db7d241..edb68bd9 100644 --- a/src/admin/query/globals.rs +++ b/src/admin/query/globals.rs @@ -32,7 +32,7 @@ pub(super) async fn process(subcommand: GlobalsCommand, context: &Context<'_>) - }, | GlobalsCommand::CurrentCount => { let timer = tokio::time::Instant::now(); - let results = services.globals.db.current_count(); + let results = services.globals.current_count(); let query_time = timer.elapsed(); write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```") diff --git a/src/service/globals/data.rs b/src/service/globals/data.rs index 386560ee..49405e04 100644 --- a/src/service/globals/data.rs +++ b/src/service/globals/data.rs @@ -38,7 +38,8 @@ impl Data { } } - pub async fn wait_pending(&self) -> Result { + #[inline] + pub(super) async fn wait_pending(&self) -> Result { let count = self.counter.dispatched(); self.wait_count(&count).await.inspect(|retired| { debug_assert!( @@ -48,7 +49,8 @@ impl Data { }) } - pub async fn wait_count(&self, count: &u64) -> Result { + #[inline] + pub(super) async fn wait_count(&self, count: &u64) -> Result { self.retires .subscribe() .wait_for(|retired| retired.ge(count)) @@ -58,17 +60,17 @@ impl Data { } #[inline] - pub fn next_count(&self) -> Permit { + pub(super) fn next_count(&self) -> Permit { self.counter .next() .expect("failed to obtain next sequence number") } #[inline] - pub fn current_count(&self) -> u64 { self.counter.current() } + pub(super) fn current_count(&self) -> u64 { self.counter.current() } #[inline] - pub fn pending_count(&self) -> Range { self.counter.range() } + pub(super) fn pending_count(&self) -> Range { self.counter.range() } fn handle_retire(sender: &Sender, count: u64) -> Result { let _prev = sender.send_replace(count); diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 90cb50a4..12a36aa3 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -105,7 +105,6 @@ impl crate::Service for Service { } impl Service { - #[inline] #[tracing::instrument( level = "trace", skip_all, @@ -114,7 +113,6 @@ impl Service { )] pub async fn wait_pending(&self) -> Result { self.db.wait_pending().await } - #[inline] #[tracing::instrument( level = "trace", skip_all, @@ -123,20 +121,17 @@ impl Service { )] pub async fn wait_count(&self, count: &u64) -> Result { self.db.wait_count(count).await } - #[inline] - #[must_use] #[tracing::instrument( level = "debug", skip_all, fields(pending = ?self.pending_count()), )] + #[must_use] pub fn next_count(&self) -> data::Permit { self.db.next_count() } - #[inline] #[must_use] pub fn current_count(&self) -> u64 { self.db.current_count() } - #[inline] #[must_use] pub fn pending_count(&self) -> Range { self.db.pending_count() } diff --git a/src/service/presence/data.rs b/src/service/presence/data.rs index de6b07cd..6e8edf8b 100644 --- a/src/service/presence/data.rs +++ b/src/service/presence/data.rs @@ -35,6 +35,7 @@ impl Data { } } + #[inline] pub(super) async fn get_presence(&self, user_id: &UserId) -> Result<(u64, PresenceEvent)> { let count = self .userid_presenceid @@ -135,6 +136,7 @@ impl Data { Ok(()) } + #[inline] pub(super) async fn remove_presence(&self, user_id: &UserId) { let Ok(count) = self .userid_presenceid diff --git a/src/service/presence/mod.rs b/src/service/presence/mod.rs index 79541b66..27b6753f 100644 --- a/src/service/presence/mod.rs +++ b/src/service/presence/mod.rs @@ -89,7 +89,6 @@ impl crate::Service for Service { impl Service { /// Returns the latest presence event for the given user. - #[inline] pub async fn get_presence(&self, user_id: &UserId) -> Result { self.db .get_presence(user_id) diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index 92f426d1..ade3705e 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -46,6 +46,7 @@ impl Data { } } + #[inline] pub(super) fn add_relation(&self, from: u64, to: u64) { const BUFSIZE: usize = size_of::() * 2; @@ -116,15 +117,18 @@ impl Data { } } + #[inline] pub(super) async fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> bool { let key = (room_id, event_id); self.referencedevents.qry(&key).await.is_ok() } + #[inline] pub(super) fn mark_event_soft_failed(&self, event_id: &EventId) { self.softfailedeventids.insert(event_id, []); } + #[inline] pub(super) async fn is_event_soft_failed(&self, event_id: &EventId) -> bool { self.softfailedeventids .get(event_id) diff --git a/src/service/rooms/pdu_metadata/mod.rs b/src/service/rooms/pdu_metadata/mod.rs index 35b58f46..0e86a8b2 100644 --- a/src/service/rooms/pdu_metadata/mod.rs +++ b/src/service/rooms/pdu_metadata/mod.rs @@ -119,7 +119,6 @@ impl Service { self.db.mark_as_referenced(room_id, event_ids); } - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub async fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> bool { self.db @@ -127,13 +126,11 @@ impl Service { .await } - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub fn mark_event_soft_failed(&self, event_id: &EventId) { self.db.mark_event_soft_failed(event_id); } - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub async fn is_event_soft_failed(&self, event_id: &EventId) -> bool { self.db.is_event_soft_failed(event_id).await diff --git a/src/service/rooms/read_receipt/data.rs b/src/service/rooms/read_receipt/data.rs index 5a0971f8..c3a43c44 100644 --- a/src/service/rooms/read_receipt/data.rs +++ b/src/service/rooms/read_receipt/data.rs @@ -40,6 +40,7 @@ impl Data { } } + #[inline] pub(super) async fn readreceipt_update( &self, user_id: &UserId, @@ -62,6 +63,7 @@ impl Data { .put(latest_id, Json(event)); } + #[inline] pub(super) fn readreceipts_since<'a>( &'a self, room_id: &'a RoomId, @@ -90,6 +92,7 @@ impl Data { .ignore_err() } + #[inline] pub(super) fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, pdu_count: u64) { let key = (room_id, user_id); let next_count = self.services.globals.next_count(); @@ -99,6 +102,7 @@ impl Data { .put(key, *next_count); } + #[inline] pub(super) async fn private_read_get_count( &self, room_id: &RoomId, @@ -111,6 +115,7 @@ impl Data { .deserialized() } + #[inline] pub(super) async fn last_privateread_update( &self, user_id: &UserId, diff --git a/src/service/rooms/read_receipt/mod.rs b/src/service/rooms/read_receipt/mod.rs index ecb43bd5..8c80d741 100644 --- a/src/service/rooms/read_receipt/mod.rs +++ b/src/service/rooms/read_receipt/mod.rs @@ -60,6 +60,7 @@ impl Service { self.db .readreceipt_update(user_id, room_id, event) .await; + self.services .sending .flush_room(room_id) @@ -78,6 +79,7 @@ impl Service { .map_err(|e| { err!(Database(warn!("No private read receipt was set in {room_id}: {e}"))) }); + let shortroomid = self .services .short @@ -120,7 +122,6 @@ impl Service { /// Returns an iterator over the most recent read_receipts in a room that /// happened after the event with id `since`. - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub fn readreceipts_since<'a>( &'a self, @@ -132,14 +133,12 @@ impl Service { } /// Sets a private read marker at PDU `count`. - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) { self.db.private_read_set(room_id, user_id, count); } /// Returns the private read marker PDU count. - #[inline] #[tracing::instrument(skip(self), level = "debug")] pub async fn private_read_get_count( &self, @@ -152,7 +151,6 @@ impl Service { } /// Returns the PDU count of the last typing update in this room. - #[inline] pub async fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> u64 { self.db .last_privateread_update(user_id, room_id) @@ -180,8 +178,8 @@ where }, } } - let content = ReceiptEventContent::from_iter(json); + let content = ReceiptEventContent::from_iter(json); tuwunel_core::trace!(?content); Raw::from_json( serde_json::value::to_raw_value(&SyncEphemeralRoomEvent { content }) diff --git a/src/service/sending/data.rs b/src/service/sending/data.rs index 3a2b3c4e..640c76e9 100644 --- a/src/service/sending/data.rs +++ b/src/service/sending/data.rs @@ -42,6 +42,7 @@ impl Data { } } + #[inline] pub(super) fn delete_active_request(&self, key: &[u8]) { self.servercurrentevent_data.remove(key); }