Skip to content

Commit 1c32851

Browse files
committed
paginator: don't use async_trait for PaginableRoom
This divides compile times for matrix-sdk by 2, on my machine (33 seconds -> 16).
1 parent 59535ed commit 1c32851

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

crates/matrix-sdk-ui/src/timeline/tests/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ impl TestRoomDataProvider {
304304
}
305305
}
306306

307-
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
308-
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
309307
impl PaginableRoom for TestRoomDataProvider {
310308
async fn event_with_context(
311309
&self,

crates/matrix-sdk/src/event_cache/paginator.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! makes it possible to paginate forward or backward, from that event, until
1818
//! one end of the timeline (front or back) is reached.
1919
20-
use std::sync::Mutex;
20+
use std::{future::Future, sync::Mutex};
2121

2222
use eyeball::{SharedObservable, Subscriber};
2323
use matrix_sdk_base::{deserialized_responses::TimelineEvent, SendOutsideWasm, SyncOutsideWasm};
@@ -431,37 +431,35 @@ impl<PR: PaginableRoom> Paginator<PR> {
431431
///
432432
/// Not [`crate::Room`] because we may want to paginate rooms we don't belong
433433
/// to.
434-
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
435-
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
436434
pub trait PaginableRoom: SendOutsideWasm + SyncOutsideWasm {
437435
/// Runs a /context query for the given room.
438436
///
439437
/// ## Parameters
440438
///
441439
/// - `event_id` is the identifier of the target event.
442440
/// - `lazy_load_members` controls whether room membership events are lazily
443-
/// loaded as context
444-
/// state events.
441+
/// loaded as context state events.
445442
/// - `num_events` is the number of events (including the fetched event) to
446-
/// return as context.
443+
/// return as context.
447444
///
448445
/// ## Returns
449446
///
450447
/// Must return [`PaginatorError::EventNotFound`] whenever the target event
451448
/// could not be found, instead of causing an http `Err` result.
452-
async fn event_with_context(
449+
fn event_with_context(
453450
&self,
454451
event_id: &EventId,
455452
lazy_load_members: bool,
456453
num_events: UInt,
457-
) -> Result<EventWithContextResponse, PaginatorError>;
454+
) -> impl Future<Output = Result<EventWithContextResponse, PaginatorError>> + Send;
458455

459456
/// Runs a /messages query for the given room.
460-
async fn messages(&self, opts: MessagesOptions) -> Result<Messages, PaginatorError>;
457+
fn messages(
458+
&self,
459+
opts: MessagesOptions,
460+
) -> impl Future<Output = Result<Messages, PaginatorError>> + Send;
461461
}
462462

463-
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
464-
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
465463
impl PaginableRoom for Room {
466464
async fn event_with_context(
467465
&self,
@@ -474,8 +472,9 @@ impl PaginableRoom for Room {
474472
Ok(result) => result,
475473

476474
Err(err) => {
477-
// If the error was a 404, then the event wasn't found on the server; special
478-
// case this to make it easy to react to such an error.
475+
// If the error was a 404, then the event wasn't found on the server;
476+
// special case this to make it easy to react to
477+
// such an error.
479478
if let Some(error) = err.as_client_api_error() {
480479
if error.status_code == 404 {
481480
// Event not found
@@ -496,8 +495,6 @@ impl PaginableRoom for Room {
496495
}
497496
}
498497

499-
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
500-
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
501498
impl PaginableRoom for WeakRoom {
502499
async fn event_with_context(
503500
&self,
@@ -513,7 +510,6 @@ impl PaginableRoom for WeakRoom {
513510
PaginableRoom::event_with_context(&room, event_id, lazy_load_members, num_events).await
514511
}
515512

516-
/// Runs a /messages query for the given room.
517513
async fn messages(&self, opts: MessagesOptions) -> Result<Messages, PaginatorError> {
518514
let Some(room) = self.get() else {
519515
// Client is shutting down, return a default response.
@@ -529,7 +525,6 @@ mod tests {
529525
use std::sync::Arc;
530526

531527
use assert_matches2::assert_let;
532-
use async_trait::async_trait;
533528
use futures_core::Future;
534529
use futures_util::FutureExt as _;
535530
use matrix_sdk_base::deserialized_responses::TimelineEvent;
@@ -589,7 +584,6 @@ mod tests {
589584
static ROOM_ID: Lazy<&RoomId> = Lazy::new(|| room_id!("!dune:herbert.org"));
590585
static USER_ID: Lazy<&UserId> = Lazy::new(|| user_id!("@paul:atreid.es"));
591586

592-
#[async_trait]
593587
impl PaginableRoom for TestRoom {
594588
async fn event_with_context(
595589
&self,
@@ -1089,7 +1083,6 @@ mod tests {
10891083
}
10901084
}
10911085

1092-
#[async_trait]
10931086
impl PaginableRoom for AbortingRoom {
10941087
async fn event_with_context(
10951088
&self,

0 commit comments

Comments
 (0)