From bb36a2c3982e11156e5a9eb7d37523e285f85de7 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 15 Jun 2019 15:20:32 -0700 Subject: [PATCH] ircd::m::dbs: Fix the _room_state_space comparator. --- ircd/m_dbs.cc | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/ircd/m_dbs.cc b/ircd/m_dbs.cc index 3cc8252e5..8b16f8f13 100644 --- a/ircd/m_dbs.cc +++ b/ircd/m_dbs.cc @@ -3235,10 +3235,38 @@ ircd::m::dbs::desc::events__room_state_space__cmp if(empty(post[1])) return false; - // Perform standard comparison over the typed tuple. - const auto _a(room_state_space_key(post[0])); - const auto _b(room_state_space_key(post[1])); - return _a < _b; + // Decompose the postfix of the key for granular sorting + const room_state_space_key_parts k[2] + { + room_state_space_key(post[0]), + room_state_space_key(post[1]) + }; + + // type + if(std::get<0>(k[0]) < std::get<0>(k[1])) + return true; + else if(std::get<0>(k[0]) > std::get<0>(k[1])) + return false; + + // state_key + if(std::get<1>(k[0]) < std::get<1>(k[1])) + return true; + else if(std::get<1>(k[0]) > std::get<1>(k[1])) + return false; + + // depth (ORDER IS DESCENDING!) + if(std::get<2>(k[0]) > std::get<2>(k[1])) + return true; + else if(std::get<2>(k[0]) < std::get<2>(k[1])) + return false; + + // event_idx (ORDER IS DESCENDING!) + if(std::get<3>(k[0]) > std::get<3>(k[1])) + return true; + else if(std::get<3>(k[0]) < std::get<3>(k[1])) + return false; + + return false; }, // equal @@ -3268,7 +3296,7 @@ ircd::m::dbs::desc::events__room_state_space {}, // comparator - {}, + events__room_state_space__cmp, // prefix transform events__room_state_space__pfx,