Skip to content

Commit

Permalink
ircd::m::relates: Add conf item for non-type coarse control of sortin…
Browse files Browse the repository at this point in the history
…g field.
  • Loading branch information
jevolk committed May 1, 2023
1 parent b6cb118 commit 4fe8580
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/ircd/m/relates.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ struct ircd::m::relates
const event::idx &, const json::object &, const m::relates_to &
>;

static conf::item<std::string> latest_column;

event::refs refs;
bool match_sender {false};
bool prefetch_depth {false};
bool prefetch_latest {false};
bool prefetch_sender {false};

private:
Expand Down
22 changes: 17 additions & 5 deletions matrix/relates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
// copyright notice and this permission notice is present in all copies. The
// 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
ircd::m::relates::prefetch(const string_view &type)
const
Expand All @@ -21,8 +28,8 @@ const
refs.for_each(dbs::ref::M_RELATES, [this, &ret]
(const auto &event_idx, const auto &)
{
if(this->prefetch_depth)
ret |= m::prefetch(event_idx, "depth");
if(this->prefetch_latest)
ret |= m::prefetch(event_idx, string_view{latest_column});

if(this->prefetch_sender || this->match_sender)
ret |= m::prefetch(event_idx, "sender");
Expand Down Expand Up @@ -87,6 +94,11 @@ ircd::m::relates::latest(const string_view &type,
uint *const at)
const
{
const string_view &column
{
latest_column
};

if(at)
*at = -1;

Expand All @@ -97,10 +109,10 @@ const
(const event::idx &event_idx, const json::object &, const m::relates_to &)
noexcept
{
int64_t depth{0};
if((depth = m::get(std::nothrow, event_idx, "depth", depth)) > best)
int64_t val{0};
if((val = m::get(std::nothrow, event_idx, column, val)) > best)
{
best = depth;
best = val;
ret = event_idx;

if(at)
Expand Down

0 comments on commit 4fe8580

Please sign in to comment.