Skip to content

Commit f23fd18

Browse files
committed
Merge branch 'main' into feat-sliding-sync-room
2 parents ab96a69 + 149950c commit f23fd18

File tree

18 files changed

+426
-205
lines changed

18 files changed

+426
-205
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ publish = false
1111
criterion = { version = "0.4.0", features = ["async", "async_tokio", "html_reports"] }
1212
matrix-sdk-crypto = { path = "../crates/matrix-sdk-crypto", version = "0.6.0"}
1313
matrix-sdk-sqlite = { path = "../crates/matrix-sdk-sqlite", version = "0.1.0", default-features = false, features = ["crypto-store"] }
14+
matrix-sdk-sled = { path = "../crates/matrix-sdk-sled", version = "0.2.0", default-features = false, features = ["crypto-store"] }
1415
matrix-sdk-test = { path = "../testing/matrix-sdk-test", version = "0.6.0"}
1516
ruma = { workspace = true }
1617
serde_json = { workspace = true }

benchmarks/benches/crypto_bench.rs

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{ops::Deref, sync::Arc};
22

33
use criterion::*;
44
use matrix_sdk_crypto::{EncryptionSettings, OlmMachine};
5+
use matrix_sdk_sled::SledCryptoStore;
56
use matrix_sdk_sqlite::SqliteCryptoStore;
67
use matrix_sdk_test::response_from_file;
78
use ruma::{
@@ -65,11 +66,15 @@ pub fn keys_query(c: &mut Criterion) {
6566

6667
let name = format!("{count} device and cross signing keys");
6768

69+
// Benchmark memory store.
70+
6871
group.bench_with_input(BenchmarkId::new("memory store", &name), &response, |b, response| {
6972
b.to_async(&runtime)
7073
.iter(|| async { machine.mark_request_as_sent(&txn_id, response).await.unwrap() })
7174
});
7275

76+
// Benchmark sqlite store.
77+
7378
let dir = tempfile::tempdir().unwrap();
7479
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
7580
let machine =
@@ -80,6 +85,23 @@ pub fn keys_query(c: &mut Criterion) {
8085
.iter(|| async { machine.mark_request_as_sent(&txn_id, response).await.unwrap() })
8186
});
8287

88+
{
89+
let _guard = runtime.enter();
90+
drop(machine);
91+
}
92+
93+
// Benchmark (deprecated) sled store.
94+
95+
let dir = tempfile::tempdir().unwrap();
96+
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
97+
let machine =
98+
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
99+
100+
group.bench_with_input(BenchmarkId::new("sled store", &name), &response, |b, response| {
101+
b.to_async(&runtime)
102+
.iter(|| async { machine.mark_request_as_sent(&txn_id, response).await.unwrap() })
103+
});
104+
83105
group.finish()
84106
}
85107

@@ -108,7 +130,10 @@ pub fn keys_claiming(c: &mut Criterion) {
108130
(machine, &runtime, &txn_id)
109131
},
110132
move |(machine, runtime, txn_id)| {
111-
runtime.block_on(machine.mark_request_as_sent(txn_id, response)).unwrap()
133+
runtime.block_on(async {
134+
machine.mark_request_as_sent(txn_id, response).await.unwrap();
135+
drop(machine);
136+
})
112137
},
113138
BatchSize::SmallInput,
114139
)
@@ -129,6 +154,31 @@ pub fn keys_claiming(c: &mut Criterion) {
129154
.unwrap();
130155
(machine, &runtime, &txn_id)
131156
},
157+
move |(machine, runtime, txn_id)| {
158+
runtime.block_on(async {
159+
machine.mark_request_as_sent(txn_id, response).await.unwrap();
160+
drop(machine)
161+
})
162+
},
163+
BatchSize::SmallInput,
164+
)
165+
});
166+
167+
group.bench_with_input(BenchmarkId::new("sled store", &name), &response, |b, response| {
168+
b.iter_batched(
169+
|| {
170+
let dir = tempfile::tempdir().unwrap();
171+
let store =
172+
Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
173+
174+
let machine = runtime
175+
.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store))
176+
.unwrap();
177+
runtime
178+
.block_on(machine.mark_request_as_sent(&txn_id, &keys_query_response))
179+
.unwrap();
180+
(machine, &runtime, &txn_id)
181+
},
132182
move |(machine, runtime, txn_id)| {
133183
runtime.block_on(machine.mark_request_as_sent(txn_id, response)).unwrap()
134184
},
@@ -160,6 +210,8 @@ pub fn room_key_sharing(c: &mut Criterion) {
160210
group.throughput(Throughput::Elements(count as u64));
161211
let name = format!("{count} devices");
162212

213+
// Benchmark memory store.
214+
163215
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
164216
b.to_async(&runtime).iter(|| async {
165217
let requests = machine
@@ -180,6 +232,9 @@ pub fn room_key_sharing(c: &mut Criterion) {
180232
machine.invalidate_group_session(room_id).await.unwrap();
181233
})
182234
});
235+
236+
// Benchmark sqlite store.
237+
183238
let dir = tempfile::tempdir().unwrap();
184239
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
185240

@@ -209,6 +264,42 @@ pub fn room_key_sharing(c: &mut Criterion) {
209264
})
210265
});
211266

267+
{
268+
let _guard = runtime.enter();
269+
drop(machine);
270+
}
271+
272+
// Benchmark (deprecated) sled store.
273+
274+
let dir = tempfile::tempdir().unwrap();
275+
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
276+
277+
let machine =
278+
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
279+
runtime.block_on(machine.mark_request_as_sent(&txn_id, &keys_query_response)).unwrap();
280+
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
281+
282+
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
283+
b.to_async(&runtime).iter(|| async {
284+
let requests = machine
285+
.share_room_key(
286+
room_id,
287+
users.iter().map(Deref::deref),
288+
EncryptionSettings::default(),
289+
)
290+
.await
291+
.unwrap();
292+
293+
assert!(!requests.is_empty());
294+
295+
for request in requests {
296+
machine.mark_request_as_sent(&request.txn_id, &to_device_response).await.unwrap();
297+
}
298+
299+
machine.invalidate_group_session(room_id).await.unwrap();
300+
})
301+
});
302+
212303
group.finish()
213304
}
214305

@@ -229,12 +320,16 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
229320

230321
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
231322

323+
// Benchmark memory store.
324+
232325
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
233326
b.to_async(&runtime).iter_with_large_drop(|| async {
234327
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
235328
})
236329
});
237330

331+
// Benchmark sqlite store.
332+
238333
let dir = tempfile::tempdir().unwrap();
239334
let store = Arc::new(runtime.block_on(SqliteCryptoStore::open(dir.path(), None)).unwrap());
240335

@@ -249,6 +344,27 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
249344
})
250345
});
251346

347+
{
348+
let _guard = runtime.enter();
349+
drop(machine);
350+
}
351+
352+
// Benchmark (deprecated) sled store.
353+
354+
let dir = tempfile::tempdir().unwrap();
355+
let store = Arc::new(runtime.block_on(SledCryptoStore::open(dir.path(), None)).unwrap());
356+
357+
let machine =
358+
runtime.block_on(OlmMachine::with_store(alice_id(), alice_device_id(), store)).unwrap();
359+
360+
runtime.block_on(machine.mark_request_as_sent(&txn_id, &response)).unwrap();
361+
362+
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
363+
b.to_async(&runtime).iter(|| async {
364+
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
365+
})
366+
});
367+
252368
group.finish()
253369
}
254370

bindings/matrix-sdk-ffi/src/api.udl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dictionary NotificationItem {
1818
string? room_canonical_alias;
1919
boolean is_noisy;
2020
boolean is_direct;
21-
boolean is_encrypted;
21+
boolean? is_encrypted;
2222
};
2323

2424
interface TimelineEvent {};
@@ -154,7 +154,15 @@ interface PaginationOptions {
154154

155155
interface RoomMessageEventContent {};
156156

157+
[Error]
158+
interface ClientError {
159+
Generic(string msg);
160+
};
161+
157162
interface MediaSource {
163+
[Name=from_json, Throws=ClientError]
164+
constructor(string json);
165+
string to_json();
158166
string url();
159167
};
160168

bindings/matrix-sdk-ffi/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use matrix_sdk::{self, encryption::CryptoStoreError, HttpError, IdParseError, StoreError};
22

3-
#[derive(Debug, thiserror::Error, uniffi::Error)]
3+
#[derive(Debug, thiserror::Error)]
44
pub enum ClientError {
55
#[error("client error: {msg}")]
66
Generic { msg: String },

bindings/matrix-sdk-ffi/src/notification.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct NotificationItem {
2121

2222
pub is_noisy: bool,
2323
pub is_direct: bool,
24-
pub is_encrypted: bool,
24+
pub is_encrypted: Option<bool>,
2525
}
2626

2727
impl NotificationItem {
@@ -46,7 +46,10 @@ impl NotificationItem {
4646
room: Room,
4747
actions: Vec<Action>,
4848
) -> anyhow::Result<Self> {
49-
let sender = room.get_member(event.sender()).await?;
49+
let sender = match &room {
50+
Room::Invited(invited) => invited.invite_details().await?.inviter,
51+
_ => room.get_member(event.sender()).await?,
52+
};
5053
let mut sender_display_name = None;
5154
let mut sender_avatar_url = None;
5255
if let Some(sender) = sender {
@@ -65,7 +68,7 @@ impl NotificationItem {
6568
room_canonical_alias: room.canonical_alias().map(|c| c.to_string()),
6669
is_noisy,
6770
is_direct: room.is_direct().await?,
68-
is_encrypted: room.is_encrypted().await?,
71+
is_encrypted: room.is_encrypted().await.ok(),
6972
};
7073
Ok(item)
7174
}

bindings/matrix-sdk-ffi/src/sliding_sync.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use matrix_sdk::ruma::{
88
v4::RoomSubscription as RumaRoomSubscription,
99
UnreadNotificationsCount as RumaUnreadNotificationsCount,
1010
},
11-
assign, IdParseError, OwnedRoomId, RoomId, UInt,
11+
assign, IdParseError, OwnedRoomId, RoomId,
1212
};
1313
pub use matrix_sdk::{
1414
room::timeline::Timeline, ruma::api::client::sync::sync_events::v4::SyncRequestListFilters,
@@ -529,9 +529,9 @@ impl SlidingSyncListBuilder {
529529
Arc::new(builder)
530530
}
531531

532-
pub fn add_range(self: Arc<Self>, from: u32, to: u32) -> Arc<Self> {
532+
pub fn add_range(self: Arc<Self>, from: u32, to_included: u32) -> Arc<Self> {
533533
let mut builder = unwrap_or_clone_arc(self);
534-
builder.inner = builder.inner.add_range(from, to);
534+
builder.inner = builder.inner.add_range(from..=to_included);
535535
Arc::new(builder)
536536
}
537537

@@ -627,15 +627,15 @@ impl SlidingSyncList {
627627
/// Remember to cancel the existing stream and fetch a new one as this will
628628
/// only be applied on the next request.
629629
pub fn set_range(&self, start: u32, end: u32) -> Result<(), SlidingSyncError> {
630-
self.inner.set_range(start, end).map_err(Into::into)
630+
self.inner.set_range(start..=end).map_err(Into::into)
631631
}
632632

633633
/// Set the ranges to fetch
634634
///
635635
/// Remember to cancel the existing stream and fetch a new one as this will
636636
/// only be applied on the next request.
637637
pub fn add_range(&self, start: u32, end: u32) -> Result<(), SlidingSyncError> {
638-
self.inner.add_range((start, end)).map_err(Into::into)
638+
self.inner.add_range(start..=end).map_err(Into::into)
639639
}
640640

641641
/// Reset the ranges
@@ -650,7 +650,7 @@ impl SlidingSyncList {
650650

651651
/// The current timeline limit
652652
pub fn get_timeline_limit(&self) -> Option<u32> {
653-
self.inner.timeline_limit().map(|limit| u32::try_from(limit).unwrap_or_default())
653+
self.inner.timeline_limit()
654654
}
655655

656656
/// The current timeline limit
@@ -660,7 +660,7 @@ impl SlidingSyncList {
660660

661661
/// Unset the current timeline limit
662662
pub fn unset_timeline_limit(&self) {
663-
self.inner.set_timeline_limit::<UInt>(None)
663+
self.inner.set_timeline_limit(None)
664664
}
665665
}
666666

bindings/matrix-sdk-ffi/src/timeline.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use matrix_sdk::{
1111
use ruma::UInt;
1212
use tracing::warn;
1313

14-
use crate::{error::TimelineError, helpers::unwrap_or_clone_arc};
14+
use crate::{
15+
error::{ClientError, TimelineError},
16+
helpers::unwrap_or_clone_arc,
17+
};
1518

1619
#[uniffi::export]
1720
pub fn media_source_from_url(url: String) -> Arc<MediaSource> {
@@ -934,6 +937,15 @@ pub enum VirtualTimelineItem {
934937

935938
#[extension_trait]
936939
pub impl MediaSourceExt for MediaSource {
940+
fn from_json(json: String) -> Result<MediaSource, ClientError> {
941+
let res = serde_json::from_str(&json)?;
942+
Ok(res)
943+
}
944+
945+
fn to_json(&self) -> String {
946+
serde_json::to_string(self).expect("Media source should always be serializable ")
947+
}
948+
937949
fn url(&self) -> String {
938950
match self {
939951
MediaSource::Plain(url) => url.to_string(),

crates/matrix-sdk-base/src/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct DebugNotification<'a>(&'a Notification);
6161
#[cfg(not(tarpaulin_include))]
6262
impl<'a> fmt::Debug for DebugNotification<'a> {
6363
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64-
f.debug_struct("DebugNotification")
64+
f.debug_struct("Notification")
6565
.field("actions", &self.0.actions)
6666
.field("event", &DebugRawEvent(&self.0.event))
6767
.field("profile_tag", &self.0.profile_tag)

0 commit comments

Comments
 (0)