0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

modules/client/sync: Optimize the room state iteration strategy.

This commit is contained in:
Jason Volk 2018-12-19 14:57:44 -08:00
parent 2d90469f6b
commit 36c1b359ab

View file

@ -1004,24 +1004,24 @@ ircd::m::sync::polylog::room_state(shortpoll &sp,
m::room::state state m::room::state state
{ {
room, &fopts room
}; };
if(bool(prefetch_state)) if(bool(prefetch_state))
state.prefetch(sp.since, sp.current); state.prefetch(sp.since, sp.current);
state.for_each([&] state.for_each([&sp, &array]
(const m::event &event) (const m::event::idx &event_idx)
{ {
if(at<"depth"_>(event) >= int64_t(sp.state_at)) if(event_idx < sp.since || event_idx >= sp.current)
return; return;
const auto &event_idx const event::fetch event
{ {
index(event, std::nothrow) event_idx, std::nothrow, &fopts
}; };
if(event_idx < sp.since || event_idx >= sp.current) if(!event.valid || at<"depth"_>(event) >= int64_t(sp.state_at))
return; return;
array.append(event); array.append(event);