0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-03-13 21:10:32 +01:00

modules: Move state rebuild from client/state to s_state.

This commit is contained in:
Jason Volk 2018-05-15 14:27:26 -07:00
parent e5da1a82e7
commit 97f38507e0
3 changed files with 61 additions and 41 deletions

View file

@ -215,43 +215,3 @@ state__iov(const room &room,
return commit(room, event, content);
}
extern "C" size_t
state__rebuild_present(const m::room &room)
{
size_t ret{0};
const auto create_id
{
room::state{room}.get("m.room.create")
};
room::messages it
{
room, create_id
};
if(!it)
return ret;
db::txn txn{*dbs::events};
for(; it; ++it)
{
const event &event{*it};
if(!defined(json::get<"state_key"_>(event)))
continue;
dbs::write_opts opts;
opts.idx = it.event_idx();
opts.present = true;
opts.history = false;
opts.head = false;
opts.refs = false;
dbs::_index__room_state(txn, event, opts);
dbs::_index__room_joined(txn, event, opts);
++ret;
}
txn();
return ret;
}

View file

@ -3178,7 +3178,7 @@ console_cmd__room__state__rebuild__present(opt &out, const string_view &line)
using prototype = size_t (const m::room &);
static m::import<prototype> state__rebuild_present
{
"client_rooms", "state__rebuild_present"
"s_state", "state__rebuild_present"
};
const size_t count

60
modules/s_state.cc Normal file
View file

@ -0,0 +1,60 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
using namespace ircd;
extern "C" size_t
state__rebuild_present(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
};
for(; it; ++it)
{
const m::event &event{*it};
if(!defined(json::get<"state_key"_>(event)))
continue;
m::dbs::write_opts opts;
opts.idx = it.event_idx();
opts.present = true;
opts.history = false;
opts.head = false;
opts.refs = false;
m::dbs::_index__room_state(txn, event, opts);
m::dbs::_index__room_joined(txn, event, opts);
++ret;
}
txn();
return ret;
}