mirror of
https://github.com/matrix-construct/construct
synced 2024-09-29 20:28:52 +02:00
ircd:Ⓜ️:dbs: Add a reverse reference for previous state in event refs index.
This commit is contained in:
parent
06c548699a
commit
3444bed245
2 changed files with 37 additions and 11 deletions
|
@ -148,6 +148,7 @@ enum class ircd::m::dbs::ref
|
|||
PREV = 0x00,
|
||||
AUTH = 0x01,
|
||||
STATE = 0x02,
|
||||
PREV_STATE = 0x04,
|
||||
|
||||
// m.receipt
|
||||
M_RECEIPT__M_READ = 0x10,
|
||||
|
|
|
@ -355,7 +355,8 @@ 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)))
|
||||
if(opts.event_refs.test(uint(ref::STATE)) ||
|
||||
opts.event_refs.test(uint(ref::PREV_STATE)))
|
||||
_index_event_refs_state(txn, event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::M_RECEIPT__M_READ)))
|
||||
|
@ -455,7 +456,8 @@ 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)));
|
||||
assert(opts.event_refs.test(uint(ref::STATE)) ||
|
||||
opts.event_refs.test(uint(ref::PREV_STATE)));
|
||||
|
||||
if(!json::get<"room_id"_>(event))
|
||||
return;
|
||||
|
@ -483,6 +485,9 @@ ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
|||
|
||||
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
||||
assert(opts.event_idx != 0 && prev_state_idx != 0);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::STATE)))
|
||||
{
|
||||
const string_view &key
|
||||
{
|
||||
event_refs_key(buf, prev_state_idx, ref::STATE, opts.event_idx)
|
||||
|
@ -497,6 +502,23 @@ ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
|||
};
|
||||
}
|
||||
|
||||
if(opts.event_refs.test(uint(ref::PREV_STATE)))
|
||||
{
|
||||
const string_view &key
|
||||
{
|
||||
event_refs_key(buf, opts.event_idx, ref::PREV_STATE, prev_state_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,
|
||||
|
@ -1314,6 +1336,9 @@ ircd::m::dbs::reflect(const ref &type)
|
|||
case ref::STATE:
|
||||
return "STATE";
|
||||
|
||||
case ref::PREV_STATE:
|
||||
return "PREV_STATE";
|
||||
|
||||
case ref::M_RECEIPT__M_READ:
|
||||
return "M_RECEIPT__M_READ";
|
||||
|
||||
|
|
Loading…
Reference in a new issue