Commit ada9f8dba8

ada9f8dba85462219a27d18f678d97e57bac8f86

parent: 58c7566527

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-11-22 20:29 UTC

connection: Use a lazy loading filter for the sync.

Layout: unified · split

src/connection.rs +29 −2
@@ -13,13 +13,16 @@ use tokio::runtime::Runtime;
1313use tracing::error;
1414use uuid::Uuid;
1515
16pub use matrix_sdk::{
16use matrix_sdk::{
1717 self,
1818 api::r0::{
1919 device::{
2020 delete_devices::Response as DeleteDevicesResponse,
2121 get_devices::Response as DevicesResponse,
2222 },
23 filter::{
24 FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter,
25 },
2326 message::{
2427 get_message_events::{
2528 Request as MessagesRequest, Response as MessagesResponse,
@@ -27,6 +30,7 @@ pub use matrix_sdk::{
2730 send_message_event::Response as RoomSendResponse,
2831 },
2932 session::login::Response as LoginResponse,
33 sync::sync_events::Filter,
3034 typing::create_typing_event::{Response as TypingResponse, Typing},
3135 uiaa::AuthData,
3236 },
@@ -321,6 +325,22 @@ impl Connection {
321325 }
322326 }
323327
328 fn sync_filter() -> FilterDefinition<'static> {
329 FilterDefinition {
330 room: RoomFilter {
331 state: RoomEventFilter {
332 lazy_load_options: LazyLoadOptions::Enabled {
333 include_redundant_members: false,
334 },
335 limit: Some(10u16.into()),
336 ..Default::default()
337 },
338 ..Default::default()
339 },
340 ..Default::default()
341 }
342 }
343
324344 /// Main client sync loop.
325345 /// This runs on the per server tokio executor.
326346 /// It communicates with the main Weechat thread using a async channel.
@@ -397,8 +417,15 @@ impl Connection {
397417 // }
398418 }
399419
420 let filter = client
421 .get_or_upload_filter("sync", Connection::sync_filter())
422 .await
423 .unwrap();
424
400425 let sync_token = client.sync_token().await;
401 let sync_settings = SyncSettings::new().timeout(DEFAULT_SYNC_TIMEOUT);
426 let sync_settings = SyncSettings::new()
427 .timeout(DEFAULT_SYNC_TIMEOUT)
428 .filter(Filter::FilterId(&filter));
402429
403430 let sync_settings = if let Some(t) = sync_token {
404431 sync_settings.token(t)