ABI encapsulations; generate leaf code in pub fn's rather than inling them.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-08-02 03:36:42 +00:00
parent fa3b72947a
commit 4b9b85f671
10 changed files with 24 additions and 21 deletions

View File

@@ -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```")

View File

@@ -38,7 +38,8 @@ impl Data {
}
}
pub async fn wait_pending(&self) -> Result<u64> {
#[inline]
pub(super) async fn wait_pending(&self) -> Result<u64> {
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<u64> {
#[inline]
pub(super) async fn wait_count(&self, count: &u64) -> Result<u64> {
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<u64> { self.counter.range() }
pub(super) fn pending_count(&self) -> Range<u64> { self.counter.range() }
fn handle_retire(sender: &Sender<u64>, count: u64) -> Result {
let _prev = sender.send_replace(count);

View File

@@ -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<u64> { 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<u64> { 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<u64> { self.db.pending_count() }

View File

@@ -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

View File

@@ -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<PresenceEvent> {
self.db
.get_presence(user_id)

View File

@@ -46,6 +46,7 @@ impl Data {
}
}
#[inline]
pub(super) fn add_relation(&self, from: u64, to: u64) {
const BUFSIZE: usize = size_of::<u64>() * 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)

View File

@@ -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

View File

@@ -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,

View File

@@ -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 })

View File

@@ -42,6 +42,7 @@ impl Data {
}
}
#[inline]
pub(super) fn delete_active_request(&self, key: &[u8]) {
self.servercurrentevent_data.remove(key);
}