0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:vm: Add option to skip any sorting/reordering for array eval.

This commit is contained in:
Jason Volk 2020-08-31 13:32:22 -07:00
parent dc3ff3bd3e
commit b0a53ffd33
2 changed files with 9 additions and 2 deletions

View file

@ -274,6 +274,10 @@ struct ircd::m::vm::opts
/// being evaluated may race through the core.
bool unique {true};
/// When true, events in array inputs are evaluated as they are provided
/// without any reordering before eval.
bool ordered {false};
/// If the input event has a reference to already-strung json we can use
/// that directly when writing to the DB. When this is false we will
/// re-stringify the event internally either from a referenced source or

View file

@ -369,10 +369,13 @@ ircd::m::vm::eval::eval(const json::array &pdus,
const vm::opts &opts)
:eval{opts}
{
std::vector<m::event> events(begin(pdus), end(pdus));
// 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));
if(likely(!opts.ordered))
std::sort(begin(events), end(events));
operator()(events);
}