0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-03 22:28:52 +02:00

modules/m_room: Add utility to clear the state root entries for all room events.

This commit is contained in:
Jason Volk 2018-11-13 17:33:18 -08:00
parent 70099d70a2
commit 5b0af2f509
2 changed files with 82 additions and 0 deletions

View file

@ -6419,6 +6419,39 @@ console_cmd__room__state__rebuild__history(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__state__history__clear(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 mods::import<prototype> state__clear_history
{
"m_room", "state__clear_history"
};
const size_t count
{
state__clear_history(room)
};
out << "done " << count << std::endl;
return true;
}
bool
console_cmd__room__state__prefetch(opt &out, const string_view &line)
{

View file

@ -467,6 +467,55 @@ state__rebuild_history(const m::room &room)
return ret;
}
//TODO: state btree.
extern "C" size_t
state__clear_history(const m::room &room)
{
static const db::gopts gopts
{
db::get::NO_CACHE
};
db::txn txn
{
*m::dbs::events
};
auto it
{
m::dbs::room_events.begin(room.room_id, gopts)
};
size_t ret{0};
for(; it; ++it, ret++)
{
const auto pair
{
m::dbs::room_events_key(it->first)
};
const auto &depth{std::get<0>(pair)};
const auto &event_idx{std::get<1>(pair)};
thread_local char buf[m::dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const string_view key
{
m::dbs::room_events_key(buf, room.room_id, depth, event_idx)
};
db::txn::append
{
txn, m::dbs::room_events,
{
db::op::SET,
key
}
};
}
txn();
return ret;
}
conf::item<ulong>
state__prefetch__yield_modulus
{