Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: lower compile times too by using async_trait less #3880

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod state;

/// Data associated to the current timeline focus.
#[derive(Debug)]
enum TimelineFocusData {
enum TimelineFocusData<P: RoomDataProvider> {
/// The timeline receives live events from the sync.
Live,

Expand All @@ -92,7 +92,7 @@ enum TimelineFocusData {
/// The event id we've started to focus on.
event_id: OwnedEventId,
/// The paginator instance.
paginator: Paginator,
paginator: Paginator<P>,
/// Number of context events to request for the first request.
num_context_events: u16,
},
Expand All @@ -108,7 +108,7 @@ pub(super) struct TimelineInner<P: RoomDataProvider = Room> {
state: Arc<RwLock<TimelineInnerState>>,

/// Inner mutable focus state.
focus: Arc<RwLock<TimelineFocusData>>,
focus: Arc<RwLock<TimelineFocusData<P>>>,

/// A [`RoomDataProvider`] implementation, providing data.
///
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
let (focus_data, is_live) = match focus {
TimelineFocus::Live => (TimelineFocusData::Live, LiveTimelineUpdatesAllowed::All),
TimelineFocus::Event { target, num_context_events } => {
let paginator = Paginator::new(Box::new(room_data_provider.clone()));
let paginator = Paginator::new(room_data_provider.clone());
(
TimelineFocusData::Event { paginator, event_id: target, num_context_events },
LiveTimelineUpdatesAllowed::None,
Expand Down
16 changes: 9 additions & 7 deletions crates/matrix-sdk-ui/src/timeline/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::{
collections::{BTreeMap, HashMap},
future::Future,
sync::Arc,
};

Expand Down Expand Up @@ -303,20 +304,21 @@ impl TestRoomDataProvider {
}
}

#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
impl PaginableRoom for TestRoomDataProvider {
async fn event_with_context(
fn event_with_context(
&self,
_event_id: &EventId,
_lazy_load_members: bool,
_num_events: UInt,
) -> Result<EventWithContextResponse, PaginatorError> {
unimplemented!();
) -> impl Future<Output = Result<EventWithContextResponse, PaginatorError>> {
async { unimplemented!() }
}

async fn messages(&self, _opts: MessagesOptions) -> Result<Messages, PaginatorError> {
unimplemented!();
fn messages(
&self,
_opts: MessagesOptions,
) -> impl Future<Output = Result<Messages, PaginatorError>> {
async { unimplemented!() }
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ struct RoomEventCacheInner {
///
/// It's protected behind a lock to avoid multiple accesses to the paginator
/// at the same time.
pagination: RoomPaginationData,
pagination: RoomPaginationData<WeakRoom>,
}

impl RoomEventCacheInner {
Expand All @@ -560,7 +560,7 @@ impl RoomEventCacheInner {
all_events,
sender,
pagination: RoomPaginationData {
paginator: Paginator::new(Box::new(weak_room)),
paginator: Paginator::new(weak_room),
waited_for_initial_prev_token: Mutex::new(false),
token_notifier: Default::default(),
},
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ use tokio::{
use tracing::{debug, instrument, trace};

use super::{
paginator::{PaginationResult, Paginator, PaginatorState},
paginator::{PaginableRoom, PaginationResult, Paginator, PaginatorState},
store::Gap,
BackPaginationOutcome, Result, RoomEventCacheInner,
};
use crate::event_cache::{linked_chunk::ChunkContent, store::RoomEvents};

#[derive(Debug)]
pub(super) struct RoomPaginationData {
pub(super) struct RoomPaginationData<PR: PaginableRoom> {
/// A notifier that we received a new pagination token.
pub token_notifier: Notify,

/// The stateful paginator instance used for the integrated pagination.
pub paginator: Paginator,
pub paginator: Paginator<PR>,

/// Have we ever waited for a previous-batch-token to come from sync? We do
/// this at most once per room, the first time we try to run backward
Expand Down
Loading
Loading