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;
13use tracing::error; 13use tracing::error;
14use uuid::Uuid; 14use uuid::Uuid;
15 15
16pub use matrix_sdk::{ 16use matrix_sdk::{
17 self, 17 self,
18 api::r0::{ 18 api::r0::{
19 device::{ 19 device::{
20 delete_devices::Response as DeleteDevicesResponse, 20 delete_devices::Response as DeleteDevicesResponse,
21 get_devices::Response as DevicesResponse, 21 get_devices::Response as DevicesResponse,
22 }, 22 },
23 filter::{
24 FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter,
25 },
23 message::{ 26 message::{
24 get_message_events::{ 27 get_message_events::{
25 Request as MessagesRequest, Response as MessagesResponse, 28 Request as MessagesRequest, Response as MessagesResponse,
@@ -27,6 +30,7 @@ pub use matrix_sdk::{
27 send_message_event::Response as RoomSendResponse, 30 send_message_event::Response as RoomSendResponse,
28 }, 31 },
29 session::login::Response as LoginResponse, 32 session::login::Response as LoginResponse,
33 sync::sync_events::Filter,
30 typing::create_typing_event::{Response as TypingResponse, Typing}, 34 typing::create_typing_event::{Response as TypingResponse, Typing},
31 uiaa::AuthData, 35 uiaa::AuthData,
32 }, 36 },
@@ -321,6 +325,22 @@ impl Connection {
321 } 325 }
322 } 326 }
323 327
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
324 /// Main client sync loop. 344 /// Main client sync loop.
325 /// This runs on the per server tokio executor. 345 /// This runs on the per server tokio executor.
326 /// It communicates with the main Weechat thread using a async channel. 346 /// It communicates with the main Weechat thread using a async channel.
@@ -397,8 +417,15 @@ impl Connection {
397 // } 417 // }
398 } 418 }
399 419
420 let filter = client
421 .get_or_upload_filter("sync", Connection::sync_filter())
422 .await
423 .unwrap();
424
400 let sync_token = client.sync_token().await; 425 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));
402 429
403 let sync_settings = if let Some(t) = sync_token { 430 let sync_settings = if let Some(t) = sync_token {
404 sync_settings.token(t) 431 sync_settings.token(t)