mirror of
https://github.com/matrix-construct/construct
synced 2025-01-16 01:26:58 +01:00
modules/m_room: Add preliminary room turbulence analysis.
This commit is contained in:
parent
8a65e1d077
commit
ac4e6b23f4
2 changed files with 87 additions and 0 deletions
|
@ -4122,6 +4122,42 @@ console_cmd__room__purge(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__dagree(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"room_id",
|
||||
}};
|
||||
|
||||
const auto &room_id
|
||||
{
|
||||
m::room_id(param.at(0))
|
||||
};
|
||||
|
||||
const m::room room
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
using prototype = size_t (const m::room &, std::vector<size_t> &);
|
||||
static m::import<prototype> dagree_histogram
|
||||
{
|
||||
"m_room", "dagree_histogram"
|
||||
};
|
||||
|
||||
std::vector<size_t> v(32, 0);
|
||||
const size_t count
|
||||
{
|
||||
dagree_histogram(room, v)
|
||||
};
|
||||
|
||||
for(size_t i(0); i < v.size(); ++i)
|
||||
out << std::setw(2) << std::right << i << ": " << v.at(i) << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// user
|
||||
//
|
||||
|
|
|
@ -243,3 +243,54 @@ head__reset(const m::room &room)
|
|||
txn();
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" size_t
|
||||
dagree_histogram(const m::room &room,
|
||||
std::vector<size_t> &vec)
|
||||
{
|
||||
static const m::event::fetch::opts fopts
|
||||
{
|
||||
m::event::keys::include
|
||||
{
|
||||
"event_id",
|
||||
"prev_events",
|
||||
},
|
||||
|
||||
db::gopts
|
||||
{
|
||||
db::get::NO_CACHE |
|
||||
db::get::NO_CHECKSUM
|
||||
}
|
||||
};
|
||||
|
||||
m::room::messages it
|
||||
{
|
||||
room, &fopts
|
||||
};
|
||||
|
||||
size_t ret{0};
|
||||
for(; it; --it)
|
||||
{
|
||||
const m::event event{*it};
|
||||
const size_t num
|
||||
{
|
||||
size(json::get<"prev_events"_>(event))
|
||||
};
|
||||
|
||||
if(unlikely(num >= vec.size()))
|
||||
{
|
||||
log::warning
|
||||
{
|
||||
"Event '%s' had %zu prev events (ignored)",
|
||||
string_view(at<"event_id"_>(event))
|
||||
};
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++vec[num];
|
||||
++ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue