mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:vm: Improve aggregated eval loop.
This commit is contained in:
parent
132f18327b
commit
b570497e75
3 changed files with 48 additions and 9 deletions
|
@ -74,13 +74,13 @@ struct ircd::m::vm::eval
|
|||
|
||||
const json::iov *issue {nullptr};
|
||||
const event *event_ {nullptr};
|
||||
json::array pdus;
|
||||
vector_view<m::event> pdus;
|
||||
|
||||
string_view room_id;
|
||||
event::id::buf event_id;
|
||||
event::conforms report;
|
||||
|
||||
static bool for_each_pdu(const std::function<bool (const json::object &)> &);
|
||||
static bool for_each_pdu(const std::function<bool (const event &)> &);
|
||||
|
||||
public:
|
||||
operator const event::id::buf &() const;
|
||||
|
|
52
ircd/m.cc
52
ircd/m.cc
|
@ -1464,13 +1464,43 @@ ircd::m::vm::eval::eval(const event &event,
|
|||
operator()(event);
|
||||
}
|
||||
|
||||
ircd::m::vm::eval::eval(const json::array &event,
|
||||
ircd::m::vm::eval::eval(const json::array &pdus,
|
||||
const vm::opts &opts)
|
||||
:opts{&opts}
|
||||
,pdus{event}
|
||||
{
|
||||
for(const json::object &pdu : this->pdus)
|
||||
operator()(pdu);
|
||||
if(pdus.size() == 1)
|
||||
{
|
||||
operator()(m::event(pdus.at(0)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort the events first to avoid complicating the evals; the events might
|
||||
// be from different rooms but it doesn't matter.
|
||||
std::vector<m::event> events(begin(pdus), end(pdus));
|
||||
std::sort(begin(events), end(events));
|
||||
this->pdus = events;
|
||||
|
||||
// Conduct each eval without letting any one exception ruin things for the
|
||||
// others, including an interrupt. The only exception is a termination.
|
||||
for(const m::event &event : this->pdus) try
|
||||
{
|
||||
// When a fault::EXISTS would not actually be revealed to the user in
|
||||
// any way we can elide a lot of grief by checking this here first and
|
||||
// skipping the event. The query path will be adequately cached anyway.
|
||||
if(~(opts.warnlog | opts.errorlog) & fault::EXISTS)
|
||||
if(m::exists(m::event::id(at<"event_id"_>(event))))
|
||||
continue;
|
||||
|
||||
operator()(event);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
catch(const ctx::terminated &)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
ircd::m::vm::eval::eval(const vm::copts &opts)
|
||||
|
@ -1497,13 +1527,21 @@ const
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const json::object &)> &closure)
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const event &)> &closure)
|
||||
{
|
||||
return for_each([&closure](eval &e)
|
||||
{
|
||||
for(const json::object &pdu : e.pdus)
|
||||
if(!closure(pdu))
|
||||
if(!empty(e.pdus))
|
||||
{
|
||||
for(const auto &pdu : e.pdus)
|
||||
if(!closure(pdu))
|
||||
return false;
|
||||
}
|
||||
else if(e.event_)
|
||||
{
|
||||
if(!closure(*e.event_))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -679,6 +679,7 @@ ircd::m::vm::execute_pdu(eval &eval,
|
|||
const auto *const &top(eval::seqmax());
|
||||
eval.sequence_shared[0] = 0;
|
||||
eval.sequence_shared[1] = 0;
|
||||
eval.sequence = 0;
|
||||
eval.sequence =
|
||||
{
|
||||
top?
|
||||
|
|
Loading…
Reference in a new issue