mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:room::head::fetch: Add opts for result limitations.
This commit is contained in:
parent
d322a0c52c
commit
e2f495c4a8
2 changed files with 14 additions and 1 deletions
|
@ -65,6 +65,12 @@ struct ircd::m::room::head::fetch::opts
|
|||
m::id::event{}, 0L, 0UL
|
||||
};
|
||||
|
||||
/// Limits total results
|
||||
size_t max_results {-1UL};
|
||||
|
||||
/// Limits results per server (spec sez 20)
|
||||
size_t max_results_per_server {32};
|
||||
|
||||
/// When true, results are stored in the head set and duplicate results
|
||||
/// are not provided to the closure. When false, the head set is not used.
|
||||
bool unique {true};
|
||||
|
|
|
@ -210,9 +210,16 @@ ircd::m::room::head::fetch::fetch(const opts &opts,
|
|||
json::get<"depth"_>(result) = depth;
|
||||
}
|
||||
|
||||
return m::for_each(prev, [this, &opts, &closure, &result]
|
||||
size_t i(0);
|
||||
return m::for_each(prev, [this, &opts, &closure, &result, &i]
|
||||
(const event::id &event_id)
|
||||
{
|
||||
if(unlikely(i++ > opts.max_results_per_server))
|
||||
return true;
|
||||
|
||||
if(unlikely(this->head.size() >= opts.max_results))
|
||||
return false;
|
||||
|
||||
auto it
|
||||
{
|
||||
this->head.lower_bound(event_id)
|
||||
|
|
Loading…
Reference in a new issue