0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 13:48:53 +02:00

ircd:Ⓜ️:room::state: Add preliminary purge_replaced() w/ console cmd.

This commit is contained in:
Jason Volk 2019-03-25 18:39:30 -07:00
parent 6b3a459d29
commit 84d4ca485b
4 changed files with 74 additions and 0 deletions

View file

@ -108,4 +108,5 @@ struct ircd::m::room::state
static size_t rebuild_history(const state &);
static size_t rebuild_present(const state &);
static bool force_present(const event &);
static size_t purge_replaced(const state &);
};

View file

@ -4049,6 +4049,19 @@ ircd::m::room::purge(const room &room)
return call(room);
}
size_t
ircd::m::room::state::purge_replaced(const state &state)
{
using prototype = size_t (const room::state &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::purge_replaced"
};
return call(state);
}
bool
ircd::m::room::state::force_present(const event &event)
{

View file

@ -7512,6 +7512,33 @@ console_cmd__room__state__force(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__state__purge__replaced(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::state state
{
room_id
};
const size_t ret
{
m::room::state::purge_replaced(state)
};
out << "erased " << ret << std::endl;
return true;
}
bool
console_cmd__room__state__rebuild__present(opt &out, const string_view &line)
{

View file

@ -561,6 +561,39 @@ ircd::m::is_complete(const room &room)
return { true, depth };
}
size_t
IRCD_MODULE_EXPORT
ircd::m::room::state::purge_replaced(const state &state)
{
db::txn txn
{
*m::dbs::events
};
size_t ret(0);
m::room::messages it
{
state.room_id, uint64_t(0)
};
if(!it)
return ret;
for(; it; ++it)
{
const m::event::idx &event_idx(it.event_idx());
if(!m::get(std::nothrow, event_idx, "state_key", [](const auto &) {}))
continue;
if(!m::event::refs(event_idx).count(m::dbs::ref::STATE))
continue;
// TODO: erase event
}
return ret;
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::state::force_present(const m::event &event)