mirror of
https://github.com/matrix-construct/construct
synced 2024-11-19 00:10:59 +01:00
ircd:Ⓜ️:dbs: Add event_refs indexer; reorg event indexers related.
This commit is contained in:
parent
725dd52185
commit
ca4ef84c9f
2 changed files with 52 additions and 4 deletions
|
@ -87,9 +87,10 @@ struct ircd::m::dbs::write_opts
|
|||
db::op op {db::op::SET};
|
||||
bool present {true};
|
||||
bool history {true};
|
||||
bool indexer {true};
|
||||
bool room_head {true};
|
||||
bool room_refs {true};
|
||||
bool event_id {true};
|
||||
bool event_refs {true};
|
||||
bool json_source {false};
|
||||
};
|
||||
|
||||
|
@ -243,6 +244,8 @@ namespace ircd::m::dbs
|
|||
string_view _index_redact(db::txn &, const event &, const write_opts &);
|
||||
string_view _index_other(db::txn &, const event &, const write_opts &);
|
||||
string_view _index_room(db::txn &, const event &, const write_opts &);
|
||||
void _index_event_refs(db::txn &, const event &, const write_opts &);
|
||||
void _index_event_id(db::txn &, const event &, const write_opts &);
|
||||
void _index_event(db::txn &, const event &, const write_opts &);
|
||||
void _append_json(db::txn &, const event &, const write_opts &);
|
||||
void _append_cols(db::txn &, const event &, const write_opts &);
|
||||
|
|
|
@ -199,9 +199,7 @@ ircd::m::dbs::write(db::txn &txn,
|
|||
"Cannot write to database: no index specified for event."
|
||||
};
|
||||
|
||||
// event_idx
|
||||
if(opts.indexer)
|
||||
_index_event(txn, event, opts);
|
||||
_index_event(txn, event, opts);
|
||||
|
||||
// direct columns
|
||||
_append_cols(txn, event, opts);
|
||||
|
@ -309,6 +307,19 @@ void
|
|||
ircd::m::dbs::_index_event(db::txn &txn,
|
||||
const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
// event_id
|
||||
if(opts.event_id)
|
||||
_index_event_id(txn, event, opts);
|
||||
|
||||
if(opts.event_refs)
|
||||
_index_event_refs(txn, event, opts);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::dbs::_index_event_id(db::txn &txn,
|
||||
const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
db::txn::append
|
||||
{
|
||||
|
@ -321,6 +332,40 @@ ircd::m::dbs::_index_event(db::txn &txn,
|
|||
};
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::dbs::_index_event_refs(db::txn &txn,
|
||||
const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const event::prev &prev{event};
|
||||
for(size_t i(0); i < prev.prev_events_count(); ++i)
|
||||
{
|
||||
const event::id &prev_id{prev.prev_event(i)};
|
||||
const event::idx &prev_idx
|
||||
{
|
||||
m::index(prev_id, std::nothrow) // query
|
||||
};
|
||||
|
||||
if(!prev_idx)
|
||||
continue;
|
||||
|
||||
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
||||
assert(opts.event_idx != 0 && prev_idx != 0);
|
||||
const string_view &key
|
||||
{
|
||||
event_refs_key(buf, prev_idx, opts.event_idx)
|
||||
};
|
||||
|
||||
db::txn::append
|
||||
{
|
||||
txn, dbs::event_refs,
|
||||
{
|
||||
opts.op, key, string_view{}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::dbs::_index_room(db::txn &txn,
|
||||
const event &event,
|
||||
|
|
Loading…
Reference in a new issue