0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:room::state: Add central interface linkage for state utils.

This commit is contained in:
Jason Volk 2019-02-28 14:46:37 -08:00
parent c969eb2792
commit 66249c620f
5 changed files with 128 additions and 70 deletions

View file

@ -92,4 +92,10 @@ struct ircd::m::room::state
state() = default;
state(const state &) = delete;
state &operator=(const state &) = delete;
static size_t prefetch(const state &, const string_view &, const event::idx_range &);
static size_t clear_history(const state &);
static size_t rebuild_history(const state &);
static size_t rebuild_present(const state &);
static bool force_present(const event &);
};

View file

@ -3408,28 +3408,71 @@ ircd::m::user::room_account_data::_type(const mutable_buffer &out,
// m/room.h
//
size_t
ircd::m::room::state::prefetch(const event::idx &start,
const event::idx &stop)
const
bool
ircd::m::room::state::force_present(const event &event)
{
return prefetch(string_view{}, start, stop);
using prototype = bool (const m::event &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::force_present"
};
return call(event);
}
size_t
ircd::m::room::state::prefetch(const string_view &type,
const event::idx &start,
const event::idx &stop)
const
ircd::m::room::state::rebuild_present(const state &state)
{
using prototype = size_t (const state &, const string_view &, const std::pair<event::idx, event::idx> &);
using prototype = bool (const room::state &);
static mods::import<prototype> function
static mods::import<prototype> call
{
"m_room", "state__prefetch"
"m_room", "ircd::m::room::state::rebuild_present"
};
return function(*this, type, std::pair<event::idx, event::idx>{start, stop});
return call(state);
}
size_t
ircd::m::room::state::rebuild_history(const state &state)
{
using prototype = bool (const room::state &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::rebuild_history"
};
return call(state);
}
size_t
ircd::m::room::state::clear_history(const state &state)
{
using prototype = bool (const room::state &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::clear_history"
};
return call(state);
}
size_t
ircd::m::room::state::prefetch(const state &state,
const string_view &type,
const event::idx_range &range)
{
using prototype = size_t (const room::state &, const string_view &, const event::idx_range &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::prefetch"
};
return call(state, type, range);
}
ircd::m::room

View file

@ -910,6 +910,23 @@ ircd::m::room::state::state(const m::room &room,
{
}
size_t
ircd::m::room::state::prefetch(const event::idx &start,
const event::idx &stop)
const
{
return prefetch(string_view{}, start, stop);
}
size_t
ircd::m::room::state::prefetch(const string_view &type,
const event::idx &start,
const event::idx &stop)
const
{
return prefetch(*this, type, event::idx_range{start, stop});
}
ircd::m::event::idx
ircd::m::room::state::get(const string_view &type,
const string_view &state_key)

View file

@ -6870,15 +6870,9 @@ console_cmd__room__complete(opt &out, const string_view &line)
room_id
};
using prototype = std::pair<bool, int64_t> (const m::room &);
static mods::import<prototype> is_complete
{
"m_room", "is_complete"
};
const auto res
{
is_complete(room)
m::is_complete(room)
};
out << (res.first? "YES" : "NO")
@ -7456,15 +7450,9 @@ console_cmd__room__state__force(opt &out, const string_view &line)
event_id
};
using prototype = bool (const m::event &);
static mods::import<prototype> state__force_present
{
"m_room", "state__force_present"
};
const auto res
{
state__force_present(event)
m::room::state::force_present(event)
};
out << "forced " << event_id << " into present state" << std::endl;
@ -7486,20 +7474,16 @@ console_cmd__room__state__rebuild__present(opt &out, const string_view &line)
"*"_sv
};
using prototype = size_t (const m::room &);
static mods::import<prototype> state__rebuild_present
{
"m_room", "state__rebuild_present"
};
if(room_id == "*")
{
m::rooms::for_each(m::room::id::closure{[&out]
(const m::room::id &room_id)
{
const m::room room{room_id};
const m::room::state state{room};
const size_t count
{
state__rebuild_present(m::room{room_id})
m::room::state::rebuild_present(state)
};
out << "done " << room_id << " " << count << std::endl;
@ -7508,9 +7492,11 @@ console_cmd__room__state__rebuild__present(opt &out, const string_view &line)
return true;
}
const m::room room{room_id};
const m::room::state state{room};
const size_t count
{
state__rebuild_present(m::room{room_id})
state.rebuild_present(state)
};
out << "done " << room_id << " " << count << std::endl;
@ -7530,20 +7516,14 @@ console_cmd__room__state__rebuild__history(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const m::room room
const m::room::state state
{
room_id
};
using prototype = size_t (const m::room &);
static mods::import<prototype> state__rebuild_history
{
"m_room", "state__rebuild_history"
};
const size_t count
{
state__rebuild_history(room)
state.rebuild_history(state)
};
out << "done " << count << std::endl;
@ -7563,7 +7543,7 @@ console_cmd__room__state__history__clear(opt &out, const string_view &line)
m::room_id(param.at(0))
};
const m::room room
const m::room::state state
{
room_id
};
@ -7576,7 +7556,7 @@ console_cmd__room__state__history__clear(opt &out, const string_view &line)
const size_t count
{
state__clear_history(room)
state.clear_history(state)
};
out << "done " << count << std::endl;

View file

@ -346,14 +346,22 @@ ircd::m::is_complete(const room &room)
return { true, depth };
}
extern "C" bool
state__force_present(const m::event &event)
bool
IRCD_MODULE_EXPORT
ircd::m::room::state::force_present(const m::event &event)
{
db::txn txn
{
*m::dbs::events
};
if(!defined(json::get<"room_id"_>(event)))
throw error
{
"event %s is not a room event (no room_id)",
json::get<"event_id"_>(event)
};
if(!defined(json::get<"state_key"_>(event)))
throw error
{
@ -362,7 +370,7 @@ state__force_present(const m::event &event)
};
m::dbs::write_opts opts;
opts.event_idx = index(event);
opts.event_idx = m::index(event);
opts.present = true;
opts.history = false;
opts.room_head = false;
@ -375,15 +383,11 @@ state__force_present(const m::event &event)
return true;
}
extern "C" size_t
state__rebuild_present(const m::room &room)
size_t
IRCD_MODULE_EXPORT
ircd::m::room::state::rebuild_present(const state &state)
{
size_t ret{0};
const m::room::state state
{
room
};
const auto create_idx
{
state.get("m.room.create")
@ -394,6 +398,11 @@ state__rebuild_present(const m::room &room)
{ db::get::NO_CACHE }
};
const m::room room
{
state.room_id, nullptr, state.fopts
};
m::room::messages it
{
room, create_idx, &fopts
@ -429,15 +438,11 @@ state__rebuild_present(const m::room &room)
return ret;
}
extern "C" size_t
state__rebuild_history(const m::room &room)
size_t
IRCD_MODULE_EXPORT
ircd::m::room::state::rebuild_history(const state &state)
{
size_t ret{0};
const m::room::state state
{
room
};
const auto create_idx
{
state.get("m.room.create")
@ -448,6 +453,11 @@ state__rebuild_history(const m::room &room)
{ db::get::NO_CACHE }
};
const m::room room
{
state.room_id, nullptr, state.fopts
};
m::room::messages it
{
room, create_idx, &fopts
@ -512,8 +522,9 @@ state__rebuild_history(const m::room &room)
}
//TODO: state btree.
extern "C" size_t
state__clear_history(const m::room &room)
size_t
IRCD_MODULE_EXPORT
ircd::m::room::state::clear_history(const state &state)
{
static const db::gopts gopts
{
@ -527,7 +538,7 @@ state__clear_history(const m::room &room)
auto it
{
m::dbs::room_events.begin(room.room_id, gopts)
m::dbs::room_events.begin(state.room_id, gopts)
};
size_t ret{0};
@ -543,7 +554,7 @@ state__clear_history(const m::room &room)
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)
m::dbs::room_events_key(buf, state.room_id, depth, event_idx)
};
db::txn::append
@ -567,10 +578,11 @@ state__prefetch__yield_modulus
{ "default", 256L },
};
extern "C" size_t
state__prefetch(const m::room::state &state,
const string_view &type,
const std::pair<m::event::idx, m::event::idx> &range)
size_t
IRCD_MODULE_EXPORT
ircd::m::room::state::prefetch(const state &state,
const string_view &type,
const event::idx_range &range)
{
const m::event::fetch::opts &fopts
{