diff --git a/matrix/room_type.cc b/matrix/room_type.cc index 987a2fc13..f1c0f858f 100644 --- a/matrix/room_type.cc +++ b/matrix/room_type.cc @@ -59,10 +59,15 @@ bool ircd::m::room::type::for_each(const closure &closure) const { + const bool desc + { + range.second < 0 || uint64_t(range.second) < range.first + }; + char buf[dbs::ROOM_TYPE_KEY_MAX_SIZE]; const string_view &key { - dbs::room_type_key(buf, room.room_id, _type, range.first, -1UL) + dbs::room_type_key(buf, room.room_id, _type, range.first, desc? -1UL: 0UL) }; auto it @@ -70,14 +75,17 @@ const dbs::room_type.begin(key) }; - for(; it; ++it) + for(; it; desc? ++it: --it) { const auto &[_type, depth, event_idx] { dbs::room_type_key(it->first) }; - if(int64_t(depth) <= range.second) + if(desc && int64_t(depth) <= range.second) + break; + + if(!desc && int64_t(depth) >= range.second) break; if(this->_type && !prefixing && this->_type != _type)