mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 11:18:51 +02:00
ircd:Ⓜ️:dbs: Rename and document various ref types.
This commit is contained in:
parent
99e10d38dc
commit
62f1b5a539
5 changed files with 42 additions and 46 deletions
|
@ -15,21 +15,30 @@
|
||||||
/// which should be plenty of namespace. Internally event_refs_key() and
|
/// which should be plenty of namespace. Internally event_refs_key() and
|
||||||
/// event_refs store this in a high order byte of an event::idx integer. This
|
/// event_refs store this in a high order byte of an event::idx integer. This
|
||||||
/// is an alternative to having separate columns for each type of reference.
|
/// is an alternative to having separate columns for each type of reference.
|
||||||
|
///
|
||||||
|
/// NOTE: These values are written to the database and cannot be changed.
|
||||||
enum class ircd::m::dbs::ref
|
enum class ircd::m::dbs::ref
|
||||||
:uint8_t
|
:uint8_t
|
||||||
{
|
{
|
||||||
// DAG
|
/// All events which reference this event in their `prev_events`.
|
||||||
PREV = 0x00,
|
NEXT = 0x00,
|
||||||
AUTH = 0x01,
|
|
||||||
STATE = 0x02,
|
/// All power events which reference this event in their `auth_events`.
|
||||||
|
/// Non-auth/non-power events are not involved in this graph at all.
|
||||||
|
NEXT_AUTH = 0x01,
|
||||||
|
|
||||||
|
/// The next states in the transitions for a (type,state_key) cell.
|
||||||
|
NEXT_STATE = 0x02,
|
||||||
|
|
||||||
|
/// The previous states in the transitions for a (type,state_key) cell.
|
||||||
PREV_STATE = 0x04,
|
PREV_STATE = 0x04,
|
||||||
|
|
||||||
// m.receipt
|
/// All m.receipt's which target this event.
|
||||||
M_RECEIPT__M_READ = 0x10,
|
M_RECEIPT__M_READ = 0x10,
|
||||||
|
|
||||||
// m.relates_to
|
/// All m.relates_to's which target this event.
|
||||||
M_RELATES__M_REPLY = 0x20,
|
M_RELATES__M_REPLY = 0x20,
|
||||||
|
|
||||||
// m.room.redaction
|
/// All m.room.redaction's which target this event.
|
||||||
M_ROOM_REDACTION = 0x40,
|
M_ROOM_REDACTION = 0x40,
|
||||||
};
|
};
|
||||||
|
|
|
@ -405,13 +405,13 @@ ircd::m::dbs::_index_event_refs(db::txn &txn,
|
||||||
{
|
{
|
||||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||||
|
|
||||||
if(opts.event_refs.test(uint(ref::PREV)))
|
if(opts.event_refs.test(uint(ref::NEXT)))
|
||||||
_index_event_refs_prev(txn, event, opts);
|
_index_event_refs_prev(txn, event, opts);
|
||||||
|
|
||||||
if(opts.event_refs.test(uint(ref::AUTH)))
|
if(opts.event_refs.test(uint(ref::NEXT_AUTH)))
|
||||||
_index_event_refs_auth(txn, event, opts);
|
_index_event_refs_auth(txn, event, opts);
|
||||||
|
|
||||||
if(opts.event_refs.test(uint(ref::STATE)) ||
|
if(opts.event_refs.test(uint(ref::NEXT_STATE)) ||
|
||||||
opts.event_refs.test(uint(ref::PREV_STATE)))
|
opts.event_refs.test(uint(ref::PREV_STATE)))
|
||||||
_index_event_refs_state(txn, event, opts);
|
_index_event_refs_state(txn, event, opts);
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ ircd::m::dbs::_index_event_refs_prev(db::txn &txn,
|
||||||
const write_opts &opts)
|
const write_opts &opts)
|
||||||
{
|
{
|
||||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||||
assert(opts.event_refs.test(uint(ref::PREV)));
|
assert(opts.event_refs.test(uint(ref::NEXT)));
|
||||||
|
|
||||||
const event::prev &prev{event};
|
const event::prev &prev{event};
|
||||||
for(size_t i(0); i < prev.prev_events_count(); ++i)
|
for(size_t i(0); i < prev.prev_events_count(); ++i)
|
||||||
|
@ -468,7 +468,7 @@ ircd::m::dbs::_index_event_refs_prev(db::txn &txn,
|
||||||
assert(opts.event_idx != prev_idx);
|
assert(opts.event_idx != prev_idx);
|
||||||
const string_view &key
|
const string_view &key
|
||||||
{
|
{
|
||||||
event_refs_key(buf, prev_idx, ref::PREV, opts.event_idx)
|
event_refs_key(buf, prev_idx, ref::NEXT, opts.event_idx)
|
||||||
};
|
};
|
||||||
|
|
||||||
db::txn::append
|
db::txn::append
|
||||||
|
@ -487,7 +487,7 @@ ircd::m::dbs::_index_event_refs_auth(db::txn &txn,
|
||||||
const write_opts &opts)
|
const write_opts &opts)
|
||||||
{
|
{
|
||||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||||
assert(opts.event_refs.test(uint(ref::AUTH)));
|
assert(opts.event_refs.test(uint(ref::NEXT_AUTH)));
|
||||||
if(!event::auth::is_power_event(event))
|
if(!event::auth::is_power_event(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ ircd::m::dbs::_index_event_refs_auth(db::txn &txn,
|
||||||
assert(opts.event_idx != auth_idx);
|
assert(opts.event_idx != auth_idx);
|
||||||
const string_view &key
|
const string_view &key
|
||||||
{
|
{
|
||||||
event_refs_key(buf, auth_idx, ref::AUTH, opts.event_idx)
|
event_refs_key(buf, auth_idx, ref::NEXT_AUTH, opts.event_idx)
|
||||||
};
|
};
|
||||||
|
|
||||||
db::txn::append
|
db::txn::append
|
||||||
|
@ -543,7 +543,7 @@ ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
||||||
const write_opts &opts)
|
const write_opts &opts)
|
||||||
{
|
{
|
||||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||||
assert(opts.event_refs.test(uint(ref::STATE)) ||
|
assert(opts.event_refs.test(uint(ref::NEXT_STATE)) ||
|
||||||
opts.event_refs.test(uint(ref::PREV_STATE)));
|
opts.event_refs.test(uint(ref::PREV_STATE)));
|
||||||
|
|
||||||
if(!opts.present)
|
if(!opts.present)
|
||||||
|
@ -586,11 +586,11 @@ ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
||||||
assert(opts.event_idx != 0 && prev_state_idx != 0);
|
assert(opts.event_idx != 0 && prev_state_idx != 0);
|
||||||
assert(opts.event_idx != prev_state_idx);
|
assert(opts.event_idx != prev_state_idx);
|
||||||
|
|
||||||
if(opts.event_refs.test(uint(ref::STATE)))
|
if(opts.event_refs.test(uint(ref::NEXT_STATE)))
|
||||||
{
|
{
|
||||||
const string_view &key
|
const string_view &key
|
||||||
{
|
{
|
||||||
event_refs_key(buf, prev_state_idx, ref::STATE, opts.event_idx)
|
event_refs_key(buf, prev_state_idx, ref::NEXT_STATE, opts.event_idx)
|
||||||
};
|
};
|
||||||
|
|
||||||
db::txn::append
|
db::txn::append
|
||||||
|
@ -1691,26 +1691,13 @@ ircd::m::dbs::reflect(const ref &type)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case ref::PREV:
|
case ref::NEXT: return "NEXT";
|
||||||
return "PREV";
|
case ref::NEXT_AUTH: return "NEXT_AUTH";
|
||||||
|
case ref::NEXT_STATE: return "NEXT_STATE";
|
||||||
case ref::AUTH:
|
case ref::PREV_STATE: return "PREV_STATE";
|
||||||
return "AUTH";
|
case ref::M_RECEIPT__M_READ: return "M_RECEIPT__M_READ";
|
||||||
|
case ref::M_RELATES__M_REPLY: return "M_RELATES__M_REPLY";
|
||||||
case ref::STATE:
|
case ref::M_ROOM_REDACTION: return "M_ROOM_REDACTION";
|
||||||
return "STATE";
|
|
||||||
|
|
||||||
case ref::PREV_STATE:
|
|
||||||
return "PREV_STATE";
|
|
||||||
|
|
||||||
case ref::M_RECEIPT__M_READ:
|
|
||||||
return "M_RECEIPT__M_READ";
|
|
||||||
|
|
||||||
case ref::M_RELATES__M_REPLY:
|
|
||||||
return "M_RELATES__M_REPLY";
|
|
||||||
|
|
||||||
case ref::M_ROOM_REDACTION:
|
|
||||||
return "M_ROOM_REDACTION";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "????";
|
return "????";
|
||||||
|
|
|
@ -2429,7 +2429,7 @@ const
|
||||||
idx
|
idx
|
||||||
};
|
};
|
||||||
|
|
||||||
return erefs.for_each(dbs::ref::AUTH, [this, &type, &closure]
|
return erefs.for_each(dbs::ref::NEXT_AUTH, [this, &type, &closure]
|
||||||
(const event::idx &ref, const dbs::ref &)
|
(const event::idx &ref, const dbs::ref &)
|
||||||
{
|
{
|
||||||
bool match;
|
bool match;
|
||||||
|
@ -2690,8 +2690,8 @@ const
|
||||||
// the iteration at type value 0 and then ignoring the
|
// the iteration at type value 0 and then ignoring the
|
||||||
// type as a loop continue condition.
|
// type as a loop continue condition.
|
||||||
const bool all_type(type == dbs::ref(uint8_t(-1)));
|
const bool all_type(type == dbs::ref(uint8_t(-1)));
|
||||||
const auto &_type{all_type? dbs::ref::PREV : type};
|
const auto &_type{all_type? dbs::ref::NEXT : type};
|
||||||
assert(uint8_t(dbs::ref::PREV) == 0);
|
assert(uint8_t(dbs::ref::NEXT) == 0);
|
||||||
const string_view key
|
const string_view key
|
||||||
{
|
{
|
||||||
dbs::event_refs_key(buf, idx, _type, 0)
|
dbs::event_refs_key(buf, idx, _type, 0)
|
||||||
|
|
|
@ -86,7 +86,7 @@ ircd::m::room::state::purge_replaced(const state &state)
|
||||||
if(!m::get(std::nothrow, event_idx, "state_key", [](const auto &) {}))
|
if(!m::get(std::nothrow, event_idx, "state_key", [](const auto &) {}))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!m::event::refs(event_idx).count(m::dbs::ref::STATE))
|
if(!m::event::refs(event_idx).count(m::dbs::ref::NEXT_STATE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: erase event
|
// TODO: erase event
|
||||||
|
@ -388,10 +388,10 @@ ircd::m::room::state::next(const event::idx &event_idx,
|
||||||
event_idx
|
event_idx
|
||||||
};
|
};
|
||||||
|
|
||||||
return refs.for_each(dbs::ref::STATE, [&closure]
|
return refs.for_each(dbs::ref::NEXT_STATE, [&closure]
|
||||||
(const event::idx &event_idx, const dbs::ref &ref)
|
(const event::idx &event_idx, const dbs::ref &ref)
|
||||||
{
|
{
|
||||||
assert(ref == dbs::ref::STATE);
|
assert(ref == dbs::ref::NEXT_STATE);
|
||||||
return closure(event_idx);
|
return closure(event_idx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1712,7 +1712,7 @@ const
|
||||||
for(++coord.y; coord.y <= branch.y; ++coord.y, coord.x = 0)
|
for(++coord.y; coord.y <= branch.y; ++coord.y, coord.x = 0)
|
||||||
{
|
{
|
||||||
auto idx(0);
|
auto idx(0);
|
||||||
refs.for_each(dbs::ref::PREV, [&coord, &branch, &idx]
|
refs.for_each(dbs::ref::NEXT, [&coord, &branch, &idx]
|
||||||
(const auto &event_idx, const auto &)
|
(const auto &event_idx, const auto &)
|
||||||
{
|
{
|
||||||
if(coord.x <= branch.x)
|
if(coord.x <= branch.x)
|
||||||
|
|
|
@ -6756,7 +6756,7 @@ console_cmd__event__refs(opt &out, const string_view &line)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
console_cmd__event__refs__prev(opt &out, const string_view &line)
|
console_cmd__event__refs__next(opt &out, const string_view &line)
|
||||||
{
|
{
|
||||||
const params param{line, " ",
|
const params param{line, " ",
|
||||||
{
|
{
|
||||||
|
@ -6773,7 +6773,7 @@ console_cmd__event__refs__prev(opt &out, const string_view &line)
|
||||||
index(event_id)
|
index(event_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
refs.for_each(m::dbs::ref::PREV, [&out]
|
refs.for_each(m::dbs::ref::NEXT, [&out]
|
||||||
(const auto &idx, const auto &type)
|
(const auto &idx, const auto &type)
|
||||||
{
|
{
|
||||||
const m::event::fetch event
|
const m::event::fetch event
|
||||||
|
|
Loading…
Reference in a new issue