mirror of
https://github.com/matrix-construct/construct
synced 2025-03-13 21:10:32 +01:00
ircd:Ⓜ️:dbs: Rename opts.idx to opts.event_idx; split internal related.
This commit is contained in:
parent
d1f7dd9da6
commit
31d0f9daed
4 changed files with 32 additions and 20 deletions
|
@ -70,7 +70,7 @@ namespace ircd::m::dbs
|
|||
|
||||
struct ircd::m::dbs::write_opts
|
||||
{
|
||||
uint64_t idx {0};
|
||||
uint64_t event_idx {0};
|
||||
string_view root_in;
|
||||
mutable_buffer root_out;
|
||||
db::op op {db::op::SET};
|
||||
|
@ -150,6 +150,7 @@ namespace ircd::m::dbs
|
|||
string_view _index_state(db::txn &, const event &, const write_opts &);
|
||||
string_view _index_redact(db::txn &, const event &, const write_opts &);
|
||||
string_view _index_ephem(db::txn &, const event &, const write_opts &);
|
||||
void _index__event(db::txn &, const event &, const write_opts &);
|
||||
}
|
||||
|
||||
struct ircd::m::dbs::init
|
||||
|
|
|
@ -113,8 +113,8 @@ ircd::m::dbs::blacklist(db::txn &txn,
|
|||
{
|
||||
opts.op,
|
||||
string_view{event_id},
|
||||
opts.idx != uint64_t(-1) && opts.op == db::op::SET?
|
||||
byte_view<string_view>(opts.idx):
|
||||
opts.event_idx != uint64_t(-1) && opts.op == db::op::SET?
|
||||
byte_view<string_view>(opts.event_idx):
|
||||
string_view{}
|
||||
}
|
||||
};
|
||||
|
@ -125,25 +125,20 @@ ircd::m::dbs::write(db::txn &txn,
|
|||
const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
if(unlikely(opts.idx == 0))
|
||||
if(unlikely(opts.event_idx == 0))
|
||||
throw ircd::error
|
||||
{
|
||||
"Cannot write to database: no index specified for event."
|
||||
};
|
||||
|
||||
if(opts.indexer) db::txn::append
|
||||
{
|
||||
txn, dbs::event_idx,
|
||||
{
|
||||
opts.op,
|
||||
at<"event_id"_>(event),
|
||||
byte_view<string_view>(opts.idx)
|
||||
}
|
||||
};
|
||||
// event_idx
|
||||
if(opts.indexer)
|
||||
_index__event(txn, event, opts);
|
||||
|
||||
// Direct columns
|
||||
db::txn::append
|
||||
{
|
||||
txn, byte_view<string_view>(opts.idx), event, event_column, opts.op
|
||||
txn, byte_view<string_view>(opts.event_idx), event, event_column, opts.op
|
||||
};
|
||||
|
||||
if(opts.head || opts.refs)
|
||||
|
@ -162,6 +157,22 @@ ircd::m::dbs::write(db::txn &txn,
|
|||
// Internal interface
|
||||
//
|
||||
|
||||
void
|
||||
ircd::m::dbs::_index__event(db::txn &txn,
|
||||
const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
db::txn::append
|
||||
{
|
||||
txn, dbs::event_idx,
|
||||
{
|
||||
opts.op,
|
||||
at<"event_id"_>(event),
|
||||
byte_view<string_view>(opts.event_idx)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::dbs::_index_ephem(db::txn &txn,
|
||||
const event &event,
|
||||
|
@ -279,7 +290,7 @@ ircd::m::dbs::_index__room_head(db::txn &txn,
|
|||
{
|
||||
opts.op,
|
||||
key,
|
||||
byte_view<string_view>{opts.idx}
|
||||
byte_view<string_view>{opts.event_idx}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -327,7 +338,7 @@ ircd::m::dbs::_index__room_events(db::txn &txn,
|
|||
thread_local char buf[ROOM_EVENTS_KEY_MAX_SIZE];
|
||||
const string_view &key
|
||||
{
|
||||
room_events_key(buf, at<"room_id"_>(event), at<"depth"_>(event), opts.idx)
|
||||
room_events_key(buf, at<"room_id"_>(event), at<"depth"_>(event), opts.event_idx)
|
||||
};
|
||||
|
||||
db::txn::append
|
||||
|
@ -417,7 +428,7 @@ ircd::m::dbs::_index__room_state(db::txn &txn,
|
|||
|
||||
const string_view val
|
||||
{
|
||||
byte_view<string_view>(opts.idx)
|
||||
byte_view<string_view>(opts.event_idx)
|
||||
};
|
||||
|
||||
const db::op op
|
||||
|
|
|
@ -2406,7 +2406,7 @@ console_cmd__event__erase(opt &out, const string_view &line)
|
|||
|
||||
m::dbs::write_opts opts;
|
||||
opts.op = db::op::DELETE;
|
||||
opts.idx = index(event);
|
||||
opts.event_idx = index(event);
|
||||
m::dbs::write(txn, event, opts);
|
||||
txn();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ state__rebuild_present(const m::room &room)
|
|||
continue;
|
||||
|
||||
m::dbs::write_opts opts;
|
||||
opts.idx = it.event_idx();
|
||||
opts.event_idx = it.event_idx();
|
||||
opts.present = true;
|
||||
opts.history = false;
|
||||
opts.head = false;
|
||||
|
@ -106,7 +106,7 @@ state__rebuild_history(const m::room &room)
|
|||
for(; it; ++it)
|
||||
{
|
||||
const m::event &event{*it};
|
||||
opts.idx = it.event_idx();
|
||||
opts.event_idx = it.event_idx();
|
||||
if(at<"depth"_>(event) == depth + 1)
|
||||
++depth;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue