improvement: optimize /sync response
parent
0067f49d52
commit
b4d65ab67d
|
@ -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",
|
||||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -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" }
|
||||||
|
|
|
@ -2338,50 +2338,51 @@ 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 {
|
events: db
|
||||||
account_data: Some(sync_events::AccountData {
|
.account_data
|
||||||
events: db
|
.changes_since(Some(&room_id), &user_id, since)
|
||||||
.account_data
|
.unwrap()
|
||||||
.changes_since(Some(&room_id), &user_id, since)
|
.into_iter()
|
||||||
.unwrap()
|
.map(|(_, v)| v)
|
||||||
.into_iter()
|
.collect(),
|
||||||
.map(|(_, v)| v)
|
|
||||||
.collect(),
|
|
||||||
}),
|
|
||||||
summary: sync_events::RoomSummary {
|
|
||||||
heroes,
|
|
||||||
joined_member_count: joined_member_count.map(|n| (n as u32).into()),
|
|
||||||
invited_member_count: invited_member_count.map(|n| (n as u32).into()),
|
|
||||||
},
|
|
||||||
unread_notifications: sync_events::UnreadNotificationsCount {
|
|
||||||
highlight_count: None,
|
|
||||||
notification_count,
|
|
||||||
},
|
|
||||||
timeline: sync_events::Timeline {
|
|
||||||
limited: if limited || joined_since_last_sync {
|
|
||||||
Some(true)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
prev_batch,
|
|
||||||
events: room_events,
|
|
||||||
},
|
|
||||||
// TODO: state before timeline
|
|
||||||
state: sync_events::State {
|
|
||||||
events: if joined_since_last_sync {
|
|
||||||
state
|
|
||||||
.into_iter()
|
|
||||||
.map(|(_, pdu)| pdu.to_state_event())
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ephemeral: sync_events::Ephemeral { events: edus },
|
|
||||||
},
|
},
|
||||||
);
|
summary: sync_events::RoomSummary {
|
||||||
|
heroes,
|
||||||
|
joined_member_count: joined_member_count.map(|n| (n as u32).into()),
|
||||||
|
invited_member_count: invited_member_count.map(|n| (n as u32).into()),
|
||||||
|
},
|
||||||
|
unread_notifications: sync_events::UnreadNotificationsCount {
|
||||||
|
highlight_count: None,
|
||||||
|
notification_count,
|
||||||
|
},
|
||||||
|
timeline: sync_events::Timeline {
|
||||||
|
limited: if limited || joined_since_last_sync {
|
||||||
|
Some(true)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
prev_batch,
|
||||||
|
events: room_events,
|
||||||
|
},
|
||||||
|
// TODO: state before timeline
|
||||||
|
state: sync_events::State {
|
||||||
|
events: if joined_since_last_sync {
|
||||||
|
state
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_, pdu)| pdu.to_state_event())
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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,38 +2418,40 @@ 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 {
|
timeline: sync_events::Timeline {
|
||||||
account_data: Some(sync_events::AccountData { events: Vec::new() }),
|
limited: Some(false),
|
||||||
timeline: sync_events::Timeline {
|
prev_batch: Some(next_batch.clone()),
|
||||||
limited: Some(false),
|
events: room_events,
|
||||||
prev_batch: Some(next_batch.clone()),
|
|
||||||
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(),
|
invite_state: sync_events::InviteState {
|
||||||
sync_events::InvitedRoom {
|
events: db
|
||||||
invite_state: sync_events::InviteState {
|
.rooms
|
||||||
events: db
|
.room_state(&room_id)
|
||||||
.rooms
|
.unwrap()
|
||||||
.room_state(&room_id)
|
.into_iter()
|
||||||
.unwrap()
|
.map(|(_, pdu)| pdu.to_stripped_state_event())
|
||||||
.into_iter()
|
.collect(),
|
||||||
.map(|(_, pdu)| pdu.to_stripped_state_event())
|
|
||||||
.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 {
|
||||||
})
|
Vec::new()
|
||||||
} else {
|
},
|
||||||
None // TODO: left
|
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 {
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue