ircd:Ⓜ️:relates: Add conf item for non-type coarse control of sorting field.

This commit is contained in:
Jason Volk 2023-04-29 21:10:26 -07:00
parent b6cb1180f7
commit 4fe85805bf
2 changed files with 20 additions and 6 deletions

View File

@ -44,9 +44,11 @@ struct ircd::m::relates
const event::idx &, const json::object &, const m::relates_to & const event::idx &, const json::object &, const m::relates_to &
>; >;
static conf::item<std::string> latest_column;
event::refs refs; event::refs refs;
bool match_sender {false}; bool match_sender {false};
bool prefetch_depth {false}; bool prefetch_latest {false};
bool prefetch_sender {false}; bool prefetch_sender {false};
private: private:

View File

@ -8,6 +8,13 @@
// copyright notice and this permission notice is present in all copies. The // copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file. // full license for this software is available in the LICENSE file.
decltype(ircd::m::relates::latest_column)
ircd::m::relates::latest_column
{
{ "name", "ircd.m.relates.latest_column" },
{ "default", "origin_server_ts" },
};
bool bool
ircd::m::relates::prefetch(const string_view &type) ircd::m::relates::prefetch(const string_view &type)
const const
@ -21,8 +28,8 @@ const
refs.for_each(dbs::ref::M_RELATES, [this, &ret] refs.for_each(dbs::ref::M_RELATES, [this, &ret]
(const auto &event_idx, const auto &) (const auto &event_idx, const auto &)
{ {
if(this->prefetch_depth) if(this->prefetch_latest)
ret |= m::prefetch(event_idx, "depth"); ret |= m::prefetch(event_idx, string_view{latest_column});
if(this->prefetch_sender || this->match_sender) if(this->prefetch_sender || this->match_sender)
ret |= m::prefetch(event_idx, "sender"); ret |= m::prefetch(event_idx, "sender");
@ -87,6 +94,11 @@ ircd::m::relates::latest(const string_view &type,
uint *const at) uint *const at)
const const
{ {
const string_view &column
{
latest_column
};
if(at) if(at)
*at = -1; *at = -1;
@ -97,10 +109,10 @@ const
(const event::idx &event_idx, const json::object &, const m::relates_to &) (const event::idx &event_idx, const json::object &, const m::relates_to &)
noexcept noexcept
{ {
int64_t depth{0}; int64_t val{0};
if((depth = m::get(std::nothrow, event_idx, "depth", depth)) > best) if((val = m::get(std::nothrow, event_idx, column, val)) > best)
{ {
best = depth; best = val;
ret = event_idx; ret = event_idx;
if(at) if(at)