diff --git a/ircd/m.cc b/ircd/m.cc index 61f23561b..1b522a87c 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -731,15 +731,7 @@ try return false; // Skip the item for phased-sync ranges if it's not phased-sync aware. - if(!phased && data.phased && int64_t(data.range.first) < 0L) - { - assert(data.phased); - return false; - } - - // Skip the item for the initial-sync pass if it's phased-sync aware; - // it will be called for the first time at the next phase. - if(phased && data.phased && data.range.first == 0UL) + if(!phased && data.phased) return false; #ifdef RB_DEBUG diff --git a/modules/client/sync/rooms.cc b/modules/client/sync/rooms.cc index 58dbf274f..520010ea0 100644 --- a/modules/client/sync/rooms.cc +++ b/modules/client/sync/rooms.cc @@ -133,18 +133,16 @@ ircd::m::sync::_rooms_polylog(data &data, const user::rooms::closure_bool closure{[&data, &ret, &phase] (const m::room &room, const string_view &membership_) { - assert(!data.phased || int64_t(data.range.first) < 0L); - if(data.phased) { - if(phase >= int64_t(data.range.first)) - { - --phase; - return true; - } - if(phase < int64_t(data.range.first) && ret) return false; + + if(int64_t(data.range.first) < 0L) + --phase; + + if(phase > int64_t(data.range.first)) + return true; } #if defined(RB_DEBUG) @@ -160,20 +158,19 @@ ircd::m::sync::_rooms_polylog(data &data, #endif { + const scope_restore phased + { + data.phased, int64_t(data.range.first) < 0? false : data.phased + }; + const scope_restore range { - data.range.first, data.phased? 0UL : data.range.first + data.range.first, phased.theirs? 0UL : data.range.first }; ret |= _rooms_polylog_room(data, room); } - if(data.phased && !ret) - { - --data.range.first; - return true; - } - #if defined(RB_DEBUG) thread_local char tmbuf[32]; if(data.stats && rooms.stats_debug) log::debug diff --git a/modules/client/sync/rooms/state.cc b/modules/client/sync/rooms/state.cc index 73250915f..ca903ddd2 100644 --- a/modules/client/sync/rooms/state.cc +++ b/modules/client/sync/rooms/state.cc @@ -41,7 +41,10 @@ ircd::m::sync::room_state { "rooms.state", room_state_polylog, - room_state_linear + room_state_linear, + { + { "phased", true }, + } }; decltype(ircd::m::sync::room_invite_state) @@ -154,12 +157,37 @@ ircd::m::sync::room_state_polylog_events(data &data) { const m::room &room{*data.room}; const m::room::state state{room}; + json::stack::array array { *data.out, "events" }; bool ret{false}; + if(data.phased && data.range.first == 0) + { + data.room->get(std::nothrow, "m.room.create", "", [&] + (const m::event &event) + { + room_state_append(data, array, event, index(event)); + ret = true; + }); + + data.room->get(std::nothrow, "m.room.canonical_alias", "", [&] + (const m::event &event) + { + room_state_append(data, array, event, index(event)); + }); + + data.room->get(std::nothrow, "m.room.name", "", [&] + (const m::event &event) + { + room_state_append(data, array, event, index(event)); + }); + + return ret; + } + ctx::mutex mutex; const event::closure_idx each_idx{[&data, &array, &mutex, &ret] (const m::event::idx event_idx)