mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd:Ⓜ️:vm::eval: Add coarse limit to options for array evals.
This commit is contained in:
parent
023e1341a1
commit
5c7007ebef
2 changed files with 8 additions and 2 deletions
|
@ -328,6 +328,10 @@ struct ircd::m::vm::opts
|
|||
/// reason to ever adjust this.
|
||||
size_t reserve_index {1024};
|
||||
|
||||
/// Coarse limit for array evals. The counter is incremented for every
|
||||
/// event; both accepted and faulted.
|
||||
size_t limit = -1;
|
||||
|
||||
/// Mask of faults that are not thrown as exceptions out of eval(). If
|
||||
/// masked, the fault is returned from eval(). By default, the EXISTS
|
||||
/// fault is masked which means existing events won't kill eval loops.
|
||||
|
|
|
@ -370,6 +370,8 @@ ircd::m::vm::eval::eval(const json::array &pdus,
|
|||
:eval{opts}
|
||||
{
|
||||
std::vector<m::event> events(begin(pdus), end(pdus));
|
||||
if(events.size() > opts.limit)
|
||||
events.resize(opts.limit);
|
||||
|
||||
// Sort the events first to avoid complicating the evals; the events might
|
||||
// be from different rooms but it doesn't matter.
|
||||
|
@ -411,8 +413,8 @@ ircd::m::vm::eval::operator()(const vector_view<m::event> &events)
|
|||
|
||||
// Conduct each eval without letting any one exception ruin things for the
|
||||
// others, including an interrupt. The only exception is a termination.
|
||||
size_t ret(0);
|
||||
for(auto it(begin(events)); it != end(events); ++it) try
|
||||
size_t ret(0), i(0);
|
||||
for(auto it(begin(events)); it != end(events) && i < opts->limit; ++it, ++i) try
|
||||
{
|
||||
const m::event &event
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue