0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd:Ⓜ️:dbs: Add a previous state reference to refs meta index.

This commit is contained in:
Jason Volk 2019-03-11 13:38:54 -07:00
parent 5b3191345f
commit 06c548699a
2 changed files with 55 additions and 0 deletions

View file

@ -147,6 +147,7 @@ enum class ircd::m::dbs::ref
// DAG
PREV = 0x00,
AUTH = 0x01,
STATE = 0x02,
// m.receipt
M_RECEIPT__M_READ = 0x10,
@ -305,6 +306,7 @@ namespace ircd::m::dbs
void _index_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &);
void _index_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &);
void _index_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &);
void _index_event_refs_state(db::txn &, const event &, const write_opts &);
void _index_event_refs_auth(db::txn &, const event &, const write_opts &);
void _index_event_refs_prev(db::txn &, const event &, const write_opts &);
void _index_event_refs(db::txn &, const event &, const write_opts &);

View file

@ -355,6 +355,9 @@ ircd::m::dbs::_index_event_refs(db::txn &txn,
if(opts.event_refs.test(uint(ref::AUTH)))
_index_event_refs_auth(txn, event, opts);
if(opts.event_refs.test(uint(ref::STATE)))
_index_event_refs_state(txn, event, opts);
if(opts.event_refs.test(uint(ref::M_RECEIPT__M_READ)))
_index_event_refs_m_receipt_m_read(txn, event, opts);
@ -447,6 +450,53 @@ ircd::m::dbs::_index_event_refs_auth(db::txn &txn,
}
}
void
ircd::m::dbs::_index_event_refs_state(db::txn &txn,
const event &event,
const write_opts &opts)
{
assert(opts.event_refs.test(uint(ref::STATE)));
if(!json::get<"room_id"_>(event))
return;
if(!json::get<"state_key"_>(event))
return;
const m::room room
{
at<"room_id"_>(event) //TODO: ABA ABA ABA ABA
};
const m::room::state state
{
room
};
const event::idx &prev_state_idx
{
state.get(std::nothrow, at<"type"_>(event), at<"state_key"_>(event)) // query
};
if(!prev_state_idx)
return;
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
assert(opts.event_idx != 0 && prev_state_idx != 0);
const string_view &key
{
event_refs_key(buf, prev_state_idx, ref::STATE, opts.event_idx)
};
db::txn::append
{
txn, dbs::event_refs,
{
opts.op, key, string_view{}
}
};
}
void
ircd::m::dbs::_index_event_refs_m_receipt_m_read(db::txn &txn,
const event &event,
@ -1261,6 +1311,9 @@ ircd::m::dbs::reflect(const ref &type)
case ref::AUTH:
return "AUTH";
case ref::STATE:
return "STATE";
case ref::M_RECEIPT__M_READ:
return "M_RECEIPT__M_READ";