0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-18 18:08:21 +02:00

modules/client/rooms/context: Optimize queries with fetch options.

This commit is contained in:
Jason Volk 2018-09-03 02:35:11 -07:00
parent 455ba69b76
commit f4607904d2

View file

@ -33,6 +33,24 @@ flush_hiwat
{ "default", 16384L },
};
const m::event::fetch::opts
default_fetch_opts
{
m::event::keys::include
{
"content",
"depth",
"event_id",
"membership",
"origin_server_ts",
"redacts",
"room_id",
"sender",
"state_key",
"type",
},
};
resource::response
get__context(client &client,
const resource::request &request,
@ -101,7 +119,11 @@ get__context(client &client,
{
json::stack::member member{ret, "events_before"};
json::stack::array array{member};
m::room::messages before{room, event_id};
m::room::messages before
{
room, event_id, &default_fetch_opts
};
if(before)
--before;
@ -125,7 +147,11 @@ get__context(client &client,
{
json::stack::member member{ret, "events_after"};
json::stack::array array{member};
m::room::messages after{room, event_id};
m::room::messages after
{
room, event_id, &default_fetch_opts
};
if(after)
++after;
@ -148,7 +174,12 @@ get__context(client &client,
{
json::stack::member member{ret, "state"};
json::stack::array array{member};
m::room::state{room}.for_each([&array, &request]
const m::room::state state
{
room, &default_fetch_opts
};
state.for_each([&array, &request]
(const m::event &event)
{
if(!visible(event, request.user_id))