improvement: optimize /sync response

next
timokoesters 2020-06-06 22:34:08 +02:00
parent 0067f49d52
commit b4d65ab67d
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
5 changed files with 95 additions and 92 deletions

17
Cargo.lock generated
View File

@ -1263,7 +1263,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-client-api", "ruma-client-api",
@ -1277,7 +1277,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.16.1" version = "0.16.1"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding 2.1.0", "percent-encoding 2.1.0",
@ -1292,7 +1292,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.16.1" version = "0.16.1"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"proc-macro2 1.0.18", "proc-macro2 1.0.18",
"quote 1.0.6", "quote 1.0.6",
@ -1302,7 +1302,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"http", "http",
"js_int", "js_int",
@ -1319,7 +1319,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.1.3" version = "0.1.3"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"matches", "matches",
"ruma-serde", "ruma-serde",
@ -1356,8 +1356,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.2" version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
checksum = "ff655a4cb7d43b60b18e07a601889836c1c12854bb16f4c083826b664fdc55aa"
dependencies = [ dependencies = [
"js_int", "js_int",
"matches", "matches",
@ -1382,7 +1381,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.2" version = "0.2.2"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"dtoa", "dtoa",
"itoa", "itoa",
@ -1395,7 +1394,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-dev.1" version = "0.6.0-dev.1"
source = "git+https://github.com/ruma/ruma?rev=f6fb971329a4a5a7faeebf7ea47a86cd19e580f4#f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" source = "git+https://github.com/ruma/ruma?rev=12388c3fbc8ba2a685cbf0fe810c633c827f5b2c#12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
dependencies = [ dependencies = [
"base64 0.12.1", "base64 0.12.1",
"ring", "ring",

View File

@ -30,12 +30,13 @@ image = { version = "0.23.4", default-features = false, features = ["jpeg", "png
[dependencies.ruma] [dependencies.ruma]
git = "https://github.com/ruma/ruma" git = "https://github.com/ruma/ruma"
rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" rev = "12388c3fbc8ba2a685cbf0fe810c633c827f5b2c"
#path = "../ruma/ruma"
features = ["rand", "client-api", "federation-api"] features = ["rand", "client-api", "federation-api"]
# These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma # These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma
[patch.crates-io] [patch.crates-io]
ruma-api = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" } ruma-common = { git = "https://github.com/ruma/ruma", rev = "12388c3fbc8ba2a685cbf0fe810c633c827f5b2c" }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" } ruma-serde = { git = "https://github.com/ruma/ruma", rev = "12388c3fbc8ba2a685cbf0fe810c633c827f5b2c" }
ruma-events = { git = "https://github.com/ruma/ruma-events", rev = "c1ee72d" } #ruma-common = { path = "../ruma/ruma-common" }
ruma-serde = { git = "https://github.com/ruma/ruma", rev = "f6fb971329a4a5a7faeebf7ea47a86cd19e580f4" } #ruma-serde = { path = "../ruma/ruma-serde" }

View File

@ -2338,10 +2338,8 @@ pub fn sync_route(
); );
} }
joined_rooms.insert( let joined_room = sync_events::JoinedRoom {
room_id.clone().try_into().unwrap(), account_data: sync_events::AccountData {
sync_events::JoinedRoom {
account_data: Some(sync_events::AccountData {
events: db events: db
.account_data .account_data
.changes_since(Some(&room_id), &user_id, since) .changes_since(Some(&room_id), &user_id, since)
@ -2349,7 +2347,7 @@ pub fn sync_route(
.into_iter() .into_iter()
.map(|(_, v)| v) .map(|(_, v)| v)
.collect(), .collect(),
}), },
summary: sync_events::RoomSummary { summary: sync_events::RoomSummary {
heroes, heroes,
joined_member_count: joined_member_count.map(|n| (n as u32).into()), joined_member_count: joined_member_count.map(|n| (n as u32).into()),
@ -2380,8 +2378,11 @@ pub fn sync_route(
}, },
}, },
ephemeral: sync_events::Ephemeral { events: edus }, ephemeral: sync_events::Ephemeral { events: edus },
}, };
);
if !joined_room.is_empty() {
joined_rooms.insert(room_id.clone().try_into().unwrap(), joined_room);
}
} }
let mut left_rooms = BTreeMap::new(); let mut left_rooms = BTreeMap::new();
@ -2390,6 +2391,7 @@ pub fn sync_route(
let pdus = db.rooms.pdus_since(&room_id, since).unwrap(); let pdus = db.rooms.pdus_since(&room_id, since).unwrap();
let room_events = pdus.map(|pdu| pdu.unwrap().to_room_event()).collect(); let room_events = pdus.map(|pdu| pdu.unwrap().to_room_event()).collect();
// TODO: Only until leave point
let mut edus = db let mut edus = db
.rooms .rooms
.edus .edus
@ -2416,27 +2418,26 @@ pub fn sync_route(
); );
} }
left_rooms.insert( let left_room = sync_events::LeftRoom {
room_id.clone().try_into().unwrap(), account_data: sync_events::AccountData { events: Vec::new() },
sync_events::LeftRoom {
account_data: Some(sync_events::AccountData { events: Vec::new() }),
timeline: sync_events::Timeline { timeline: sync_events::Timeline {
limited: Some(false), limited: Some(false),
prev_batch: Some(next_batch.clone()), prev_batch: Some(next_batch.clone()),
events: room_events, events: room_events,
}, },
state: sync_events::State { events: Vec::new() }, state: sync_events::State { events: Vec::new() },
}, };
);
if !left_room.is_empty() {
left_rooms.insert(room_id.clone().try_into().unwrap(), left_room);
}
} }
let mut invited_rooms = BTreeMap::new(); let mut invited_rooms = BTreeMap::new();
for room_id in db.rooms.rooms_invited(&user_id) { for room_id in db.rooms.rooms_invited(&user_id) {
let room_id = room_id.unwrap(); let room_id = room_id.unwrap();
invited_rooms.insert( let invited_room = sync_events::InvitedRoom {
room_id.clone(),
sync_events::InvitedRoom {
invite_state: sync_events::InviteState { invite_state: sync_events::InviteState {
events: db events: db
.rooms .rooms
@ -2446,8 +2447,11 @@ pub fn sync_route(
.map(|(_, pdu)| pdu.to_stripped_state_event()) .map(|(_, pdu)| pdu.to_stripped_state_event())
.collect(), .collect(),
}, },
}, };
);
if !invited_room.is_empty() {
invited_rooms.insert(room_id.clone(), invited_room);
}
} }
MatrixResult(Ok(sync_events::Response { MatrixResult(Ok(sync_events::Response {
@ -2482,17 +2486,16 @@ pub fn sync_route(
.map(|(_, v)| v) .map(|(_, v)| v)
.collect(), .collect(),
}, },
device_lists: if since != 0 { device_lists: sync_events::DeviceLists {
Some(sync_events::DeviceLists { changed: if since != 0 {
changed: db db.users
.users
.device_keys_changed(since) .device_keys_changed(since)
.map(|u| u.unwrap()) .map(|u| u.unwrap())
.collect(), .collect()
left: Vec::new(), // TODO
})
} else { } else {
None // TODO: left Vec::new()
},
left: Vec::new(), // TODO
}, },
device_one_time_keys_count: Default::default(), // TODO device_one_time_keys_count: Default::default(), // TODO
to_device: sync_events::ToDevice { to_device: sync_events::ToDevice {

View File

@ -421,7 +421,7 @@ impl Rooms {
auth_events: Vec::new(), auth_events: Vec::new(),
redacts: redacts.clone(), redacts: redacts.clone(),
unsigned, unsigned,
hashes: ruma::api::federation::EventHash { hashes: ruma::api::federation::pdu::EventHash {
sha256: "aaa".to_owned(), sha256: "aaa".to_owned(),
}, },
signatures: HashMap::new(), signatures: HashMap::new(),

View File

@ -1,6 +1,6 @@
use js_int::UInt; use js_int::UInt;
use ruma::{ use ruma::{
api::federation::EventHash, api::federation::pdu::EventHash,
events::{ events::{
collections::all::{RoomEvent, StateEvent}, collections::all::{RoomEvent, StateEvent},
stripped::AnyStrippedStateEvent, stripped::AnyStrippedStateEvent,