mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️:room::state: Add preliminary purge_replaced() w/ console cmd.
This commit is contained in:
parent
6b3a459d29
commit
84d4ca485b
4 changed files with 74 additions and 0 deletions
|
@ -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 &);
|
||||
};
|
||||
|
|
13
ircd/m.cc
13
ircd/m.cc
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue