mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd:Ⓜ️ Add additional horizon rebuilders.
This commit is contained in:
parent
91cc12db84
commit
217b2d51d5
5 changed files with 126 additions and 7 deletions
|
@ -111,6 +111,8 @@ struct ircd::m::room::events::missing
|
|||
bool for_each(const closure &) const;
|
||||
size_t count() const;
|
||||
|
||||
size_t rebuild();
|
||||
|
||||
missing() = default;
|
||||
missing(const m::room &room)
|
||||
:room{room}
|
||||
|
|
|
@ -246,7 +246,7 @@ namespace ircd::m::dbs
|
|||
static void _index_event_type(db::txn &, const event &, const write_opts &);
|
||||
static void _index_event_sender(db::txn &, const event &, const write_opts &);
|
||||
static void _index_event_horizon_resolve(db::txn &, const event &, const write_opts &); //query
|
||||
static void _index_event_horizon(db::txn &, const event &, const write_opts &, const id::event &);
|
||||
void _index_event_horizon(db::txn &, const event &, const write_opts &, const id::event &);
|
||||
static void _index_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &); //query
|
||||
static void _index_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &); //query
|
||||
static void _index_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &); //query
|
||||
|
|
|
@ -1671,12 +1671,6 @@ ircd::m::index(const event::id &event_id,
|
|||
// event/horizon.h
|
||||
//
|
||||
|
||||
size_t
|
||||
ircd::m::event::horizon::rebuild()
|
||||
{
|
||||
throw not_implemented{};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::horizon::has(const event::id &event_id)
|
||||
{
|
||||
|
|
|
@ -9631,6 +9631,33 @@ console_cmd__room__events__missing(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__events__missing__rebuild(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"room_id"
|
||||
}};
|
||||
|
||||
const auto &room_id
|
||||
{
|
||||
m::room_id(param.at("room_id"))
|
||||
};
|
||||
|
||||
const m::room room
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
m::room::events::missing missing
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
out << "done " << missing.rebuild() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__messages(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
|
@ -147,3 +147,99 @@ ircd::m::pretty_stateline(std::ostream &out,
|
|||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// event/horizon.h
|
||||
//
|
||||
|
||||
//TODO: XXX remove fwd decl
|
||||
namespace ircd::m::dbs
|
||||
{
|
||||
void _index_event_horizon(db::txn &, const event &, const write_opts &, const m::event::id &);
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::event::horizon::rebuild()
|
||||
{
|
||||
m::dbs::write_opts opts;
|
||||
opts.appendix.reset();
|
||||
opts.appendix.set(dbs::appendix::EVENT_HORIZON);
|
||||
db::txn txn
|
||||
{
|
||||
*dbs::events
|
||||
};
|
||||
|
||||
size_t ret(0);
|
||||
m::events::for_each({0UL, -1UL}, [&ret, &txn, &opts]
|
||||
(const m::event::idx &event_idx, const m::event &event)
|
||||
{
|
||||
const m::event::prev prev
|
||||
{
|
||||
event
|
||||
};
|
||||
|
||||
m::for_each(prev, [&ret, &txn, &opts, &event_idx, &event]
|
||||
(const m::event::id &event_id)
|
||||
{
|
||||
if(m::exists(event_id))
|
||||
return true;
|
||||
|
||||
opts.event_idx = event_idx;
|
||||
m::dbs::_index_event_horizon(txn, event, opts, event_id);
|
||||
if(++ret % 1024 == 0)
|
||||
log::info
|
||||
{
|
||||
m::log, "event::horizon rebuild @ %lu/%lu",
|
||||
event_idx,
|
||||
m::vm::sequence::retired,
|
||||
};
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
txn();
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::events::missing::rebuild()
|
||||
{
|
||||
m::dbs::write_opts opts;
|
||||
opts.appendix.reset();
|
||||
opts.appendix.set(dbs::appendix::EVENT_HORIZON);
|
||||
db::txn txn
|
||||
{
|
||||
*dbs::events
|
||||
};
|
||||
|
||||
size_t ret(0);
|
||||
m::room::events it
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
for(; it; --it)
|
||||
{
|
||||
const m::event &event{*it};
|
||||
const event::prev prev_events{event};
|
||||
|
||||
opts.event_idx = it.event_idx();
|
||||
m::for_each(prev_events, [&]
|
||||
(const m::event::id &event_id)
|
||||
{
|
||||
if(m::exists(event_id))
|
||||
return true;
|
||||
|
||||
m::dbs::_index_event_horizon(txn, event, opts, event_id);
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
txn();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue