0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-29 08:54:02 +01:00

modules/m_room: Add head rebuilder w/ console cmd.

This commit is contained in:
Jason Volk 2018-05-22 02:58:21 -07:00
parent 53ba8dafcc
commit 8e804ff48d
2 changed files with 72 additions and 0 deletions

View file

@ -3090,6 +3090,39 @@ console_cmd__room__head(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__room__head__rebuild(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 &);
static m::import<prototype> head__rebuild
{
"m_room", "head__rebuild"
};
const size_t count
{
head__rebuild(room)
};
out << "done " << count << std::endl;
return true;
}
bool bool
console_cmd__room__depth(opt &out, const string_view &line) console_cmd__room__depth(opt &out, const string_view &line)
{ {

View file

@ -141,3 +141,42 @@ state__rebuild_history(const m::room &room)
txn(); txn();
return ret; return ret;
} }
extern "C" size_t
head__rebuild(const m::room &room)
{
size_t ret{0};
const m::room::state state{room};
const auto create_id
{
state.get("m.room.create")
};
m::room::messages it
{
room, create_id
};
if(!it)
return ret;
db::txn txn
{
*m::dbs::events
};
m::dbs::write_opts opts;
opts.op = db::op::SET;
opts.head = true;
opts.refs = true;
for(; it; ++it)
{
const m::event &event{*it};
opts.event_idx = it.event_idx();
m::dbs::_index__room_head(txn, event, opts);
++ret;
}
txn();
return ret;
}