0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 17:08:20 +02:00

ircd:Ⓜ️:user::notifications: Improve iteration with room::type.

This commit is contained in:
Jason Volk 2020-03-24 13:06:24 -07:00
parent 31fd7e664f
commit d1f9b11b4c

View file

@ -53,7 +53,6 @@ const
return ret; return ret;
} }
//TODO: XXX optimize
bool bool
ircd::m::user::notifications::for_each(const opts &opts, ircd::m::user::notifications::for_each(const opts &opts,
const closure_bool &closure) const closure_bool &closure)
@ -70,31 +69,27 @@ const
make_type(type_buf, opts) make_type(type_buf, opts)
}; };
const auto type_match{[&type](const auto &_type) const room::type events
{ {
return _type == type; user_room, type
}};
m::room::events it
{
user_room
}; };
if(opts.from) return events.for_each([&opts, &closure]
it.seek_idx(opts.from); (const auto &type, const auto &depth, const auto &event_idx)
bool ret(true);
for(; it && ret && it.event_idx() > opts.to; --it) //TODO: XXX optimize
{ {
if(!m::query(std::nothrow, it.event_idx(), "type", type_match)) if(opts.from && event_idx > opts.from) //TODO: XXX
continue; return true;
m::get(std::nothrow, it.event_idx(), "content", [&ret, &it, &closure] if(opts.to && event_idx <= opts.to) //TODO: XXX
return false;
bool ret{true};
m::get(std::nothrow, event_idx, "content", [&ret, &closure, &event_idx]
(const json::object &content) (const json::object &content)
{ {
ret = closure(it.event_idx(), content); ret = closure(event_idx, content);
}); });
}
return ret; return ret;
});
} }