0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-10 12:01:15 +01:00

ircd:Ⓜ️:events: Add event type name iteration.

ircd:Ⓜ️:events: Add sender name iteration.

ircd:Ⓜ️:events: Add origin name iteration.
This commit is contained in:
Jason Volk 2019-05-27 15:51:07 -07:00
parent 3f9fb44475
commit b403fbc421
3 changed files with 216 additions and 0 deletions

View file

@ -17,6 +17,16 @@ namespace ircd::m::events
using closure_bool = std::function<bool (const event::idx &, const event &)>;
using closure_type_bool = std::function<bool (const string_view &, const event::idx &)>;
using closure_sender_bool = std::function<bool (const id::user &, const event::idx &)>;
using closure_type_name_bool = std::function<bool (const string_view &)>;
using closure_sender_name_bool = std::function<bool (const id::user &)>;
using closure_origin_name_bool = std::function<bool (const string_view &)>;
bool for_each_type(const closure_type_name_bool &);
bool for_each_type(const string_view &prefix, const closure_type_name_bool &);
bool for_each_sender(const closure_sender_name_bool &);
bool for_each_sender(const string_view &hostlb, const closure_sender_name_bool &);
bool for_each_origin(const closure_origin_name_bool &);
bool for_each_origin(const string_view &prefix, const closure_origin_name_bool &);
bool for_each_in_type(const string_view &, const closure_type_bool &);
bool for_each_in_sender(const id::user &, const closure_sender_bool &);

137
ircd/m.cc
View file

@ -2686,6 +2686,143 @@ ircd::m::events::for_each_in_type(const string_view &type,
return true;
}
bool
ircd::m::events::for_each_type(const closure_type_name_bool &closure)
{
return for_each_type(string_view{}, closure);
}
bool
ircd::m::events::for_each_type(const string_view &prefix,
const closure_type_name_bool &closure)
{
db::column &column
{
dbs::event_type
};
const auto &prefixer
{
dbs::desc::events__event_type__pfx
};
string_view last;
char lastbuf[event::TYPE_MAX_SIZE];
for(auto it(column.lower_bound(prefix)); bool(it); ++it)
{
const auto &type
{
prefixer.get(it->first)
};
if(type == last)
continue;
if(!startswith(type, prefix))
break;
last = { lastbuf, copy(lastbuf, type) };
if(!closure(type))
return false;
}
return true;
}
bool
ircd::m::events::for_each_sender(const closure_sender_name_bool &closure)
{
return for_each_sender(string_view{}, closure);
}
bool
ircd::m::events::for_each_sender(const string_view &hostlb,
const closure_sender_name_bool &closure)
{
db::column &column
{
dbs::event_sender
};
const auto &prefixer
{
dbs::desc::events__event_sender__pfx
};
user::id::buf last;
for(auto it(column.lower_bound(hostlb)); bool(it); ++it)
{
const string_view &host
{
prefixer.get(it->first)
};
if(!startswith(host, hostlb))
break;
const auto &[localpart, event_idx]
{
dbs::event_sender_key(it->first.substr(size(host)))
};
if(last && host == last.host() && localpart == last.local())
continue;
last = m::user::id::buf
{
localpart, host
};
if(!closure(last))
return false;
}
return true;
}
bool
ircd::m::events::for_each_origin(const closure_origin_name_bool &closure)
{
return for_each_origin(string_view{}, closure);
}
bool
ircd::m::events::for_each_origin(const string_view &prefix,
const closure_origin_name_bool &closure)
{
db::column &column
{
dbs::event_sender
};
const auto &prefixer
{
dbs::desc::events__event_sender__pfx
};
string_view last;
char buf[rfc3986::DOMAIN_BUFSIZE];
for(auto it(column.lower_bound(prefix)); bool(it); ++it)
{
const string_view &host
{
prefixer.get(it->first)
};
if(host == last)
continue;
if(!startswith(host, prefix))
break;
last = { buf, copy(buf, host) };
if(!closure(host))
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// m/filter.h

View file

@ -6025,6 +6025,75 @@ console_cmd__events__in(opt &out, const string_view &line)
return console_cmd__events__in__type(out, line);
}
bool
console_cmd__events__type(opt &out, const string_view &line)
{
const params param{line, " ",
{
"prefix"
}};
const string_view &prefix
{
param["prefix"]
};
m::events::for_each_type(prefix, [&out]
(const string_view &type)
{
out << type << std::endl;
return true;
});
return true;
}
bool
console_cmd__events__sender(opt &out, const string_view &line)
{
const params param{line, " ",
{
"prefix"
}};
const string_view &prefix
{
param["prefix"]
};
m::events::for_each_sender(prefix, [&out]
(const m::user::id &user_id)
{
out << user_id << std::endl;
return true;
});
return true;
}
bool
console_cmd__events__origin(opt &out, const string_view &line)
{
const params param{line, " ",
{
"prefix"
}};
const string_view &prefix
{
param["prefix"]
};
m::events::for_each_origin(prefix, [&out]
(const string_view &origin)
{
out << origin << std::endl;
return true;
});
return true;
}
conf::item<size_t>
events_dump_buffer_size
{