0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 07:20:55 +01:00

ircd:Ⓜ️ Replace is_complete w/ sounding(); console cmd.

This commit is contained in:
Jason Volk 2019-04-26 01:08:02 -07:00
parent ba797778d6
commit 486ca09153
4 changed files with 56 additions and 28 deletions

View file

@ -28,7 +28,9 @@ namespace ircd::m
using depth_range_closure = std::function<bool (const depth_range &, const event::idx &)>; using depth_range_closure = std::function<bool (const depth_range &, const event::idx &)>;
bool for_each_depth_gap(const room &, const depth_range_closure &); bool for_each_depth_gap(const room &, const depth_range_closure &);
bool rfor_each_depth_gap(const room &, const depth_range_closure &); bool rfor_each_depth_gap(const room &, const depth_range_closure &);
std::pair<bool, int64_t> is_complete(const room &);
std::pair<int64_t, event::idx> first_missing(const room &);
std::pair<int64_t, event::idx> sounding(const room &); // Last missing
} }
/// Interface to room messages /// Interface to room messages

View file

@ -4779,6 +4779,28 @@ ircd::m::commit(const room &room,
return eval.event_id; return eval.event_id;
} }
std::pair<int64_t, ircd::m::event::idx>
ircd::m::sounding(const room &r)
{
static mods::import<decltype(sounding)> call
{
"m_room", "ircd::m::sounding"
};
return call(r);
}
std::pair<int64_t, ircd::m::event::idx>
ircd::m::first_missing(const room &r)
{
static mods::import<decltype(first_missing)> call
{
"m_room", "ircd::m::first_missing"
};
return call(r);
}
bool bool
ircd::m::rfor_each_depth_gap(const room &r, ircd::m::rfor_each_depth_gap(const room &r,
const depth_range_closure &c) const depth_range_closure &c)
@ -4807,19 +4829,6 @@ ircd::m::for_each_depth_gap(const room &r,
return call(r, c); return call(r, c);
} }
std::pair<bool, int64_t>
ircd::m::is_complete(const room &r)
{
using prototype = std::pair<bool, int64_t> (const room &);
static mods::import<prototype> call
{
"m_room", "ircd::m::is_complete"
};
return call(r);
}
size_t size_t
ircd::m::count_since(const m::event::id &a, ircd::m::count_since(const m::event::id &a,
const m::event::id &b) const m::event::id &b)

View file

@ -7371,7 +7371,7 @@ console_cmd__room__head__reset(opt &out, const string_view &line)
} }
bool bool
console_cmd__room__complete(opt &out, const string_view &line) console_cmd__room__sounding(opt &out, const string_view &line)
{ {
const params param{line, " ", const params param{line, " ",
{ {
@ -7390,12 +7390,12 @@ console_cmd__room__complete(opt &out, const string_view &line)
const auto res const auto res
{ {
m::is_complete(room) m::sounding(room)
}; };
out << (res.first? "YES" : "NO") out << "depth: " << res.first << std::endl
<< " @ depth " << res.second << "event: " << res.second << " " << m::event_id(res.second) << std::endl
<< std::endl; ;
return true; return true;
} }

View file

@ -477,21 +477,38 @@ ircd::m::room::head::for_each(const head &head,
return true; return true;
} }
std::pair<bool, int64_t> std::pair<int64_t, ircd::m::event::idx>
IRCD_MODULE_EXPORT IRCD_MODULE_EXPORT
ircd::m::is_complete(const room &room) ircd::m::sounding(const room &room)
{ {
std::pair<bool, int64_t> ret {true, -1L}; std::pair<int64_t, m::event::idx> ret
for_each_depth_gap(room, [&ret]
(const auto &range)
{ {
ret.second = range.second - 1; -1, 0
ret.first = false; };
rfor_each_depth_gap(room, [&ret]
(const auto &range, const auto &event_idx)
{
ret.first = range.second;
ret.second = event_idx;
return false; return false;
}); });
if(ret.second == -1L) return ret;
ret.first = false; }
std::pair<int64_t, ircd::m::event::idx>
IRCD_MODULE_EXPORT
ircd::m::first_missing(const room &room)
{
std::pair<int64_t, m::event::idx> ret {0, 0};
for_each_depth_gap(room, [&ret]
(const auto &range, const auto &event_idx)
{
ret.first = range.first;
ret.second = event_idx;
return false;
});
return ret; return ret;
} }