mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
Improve logs for pagination
This commit is contained in:
committed by
Jonas Platte
parent
ab7aa68c5b
commit
ee87ec7b46
@@ -1,10 +1,11 @@
|
||||
use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc};
|
||||
use std::{borrow::Borrow, collections::BTreeMap, fmt, ops::Deref, sync::Arc};
|
||||
|
||||
use matrix_sdk_base::{
|
||||
deserialized_responses::{MembersResponse, TimelineEvent},
|
||||
store::StateStoreExt,
|
||||
RoomMemberships, StateChanges,
|
||||
};
|
||||
use matrix_sdk_common::debug::DebugStructExt;
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
use ruma::events::{
|
||||
room::encrypted::OriginalSyncRoomEncryptedEvent, AnySyncMessageLikeEvent, AnySyncTimelineEvent,
|
||||
@@ -46,7 +47,7 @@ use ruma::{
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::debug;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
#[cfg(feature = "experimental-timeline")]
|
||||
use super::timeline::Timeline;
|
||||
@@ -201,6 +202,7 @@ impl Common {
|
||||
/// assert!(room.messages(options).await.is_ok());
|
||||
/// # });
|
||||
/// ```
|
||||
#[instrument(skip_all, fields(room_id = ?self.inner.room_id(), ?options))]
|
||||
pub async fn messages(&self, options: MessagesOptions) -> Result<Messages> {
|
||||
let room_id = self.inner.room_id();
|
||||
let request = options.into_request(room_id);
|
||||
@@ -1076,7 +1078,6 @@ impl Common {
|
||||
/// See that method and
|
||||
/// <https://spec.matrix.org/v1.3/client-server-api/#get_matrixclientv3roomsroomidmessages>
|
||||
/// for details.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct MessagesOptions {
|
||||
/// The token to start returning events from.
|
||||
@@ -1152,3 +1153,16 @@ impl MessagesOptions {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for MessagesOptions {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let Self { from, to, dir, limit, filter } = self;
|
||||
|
||||
let mut s = f.debug_struct("MessagesOptions");
|
||||
s.maybe_field("from", from).maybe_field("to", to).field("dir", dir).field("limit", limit);
|
||||
if !filter.is_empty() {
|
||||
s.field("filter", filter);
|
||||
}
|
||||
s.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ impl Timeline {
|
||||
}
|
||||
|
||||
/// Add more events to the start of the timeline.
|
||||
#[instrument(skip_all, fields(initial_pagination_size, room_id = ?self.room().room_id()))]
|
||||
pub async fn paginate_backwards(&self, mut opts: PaginationOptions<'_>) -> Result<()> {
|
||||
#[instrument(skip_all, fields(room_id = ?self.room().room_id(), ?options))]
|
||||
pub async fn paginate_backwards(&self, mut options: PaginationOptions<'_>) -> Result<()> {
|
||||
let mut start_lock = self.start_token.lock().await;
|
||||
if start_lock.is_none()
|
||||
&& self.inner.items().await.front().map_or(false, |item| item.is_timeline_start())
|
||||
@@ -124,7 +124,7 @@ impl Timeline {
|
||||
let mut from = start_lock.clone();
|
||||
let mut outcome = PaginationOutcome::new();
|
||||
|
||||
while let Some(limit) = opts.next_event_limit(outcome) {
|
||||
while let Some(limit) = options.next_event_limit(outcome) {
|
||||
let messages = self
|
||||
.room()
|
||||
.messages(assign!(MessagesOptions::backward(), {
|
||||
|
||||
Reference in New Issue
Block a user