mirror of
https://github.com/matrix-construct/construct
synced 2024-10-04 14:48:56 +02:00
modules/m_event: Add event refs rebuild util w/ console cmd.
This commit is contained in:
parent
2b3aec68ee
commit
f21c08fb19
2 changed files with 75 additions and 0 deletions
|
@ -5852,6 +5852,20 @@ console_cmd__event__refs(opt &out, const string_view &line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
console_cmd__event__refs__rebuild(opt &out, const string_view &line)
|
||||||
|
{
|
||||||
|
using prototype = void ();
|
||||||
|
static mods::import<prototype> rebuild
|
||||||
|
{
|
||||||
|
"m_event", "event_refs__rebuild"
|
||||||
|
};
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
out << "done" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// state
|
// state
|
||||||
//
|
//
|
||||||
|
|
|
@ -556,3 +556,64 @@ pretty_oneline__prev(std::ostream &s,
|
||||||
s << unquote(prev_event[0]) << " ";
|
s << unquote(prev_event[0]) << " ";
|
||||||
s << "] ";
|
s << "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
event_refs__rebuild()
|
||||||
|
{
|
||||||
|
static const size_t pool_size{64};
|
||||||
|
static const size_t log_interval{8192};
|
||||||
|
|
||||||
|
db::txn txn
|
||||||
|
{
|
||||||
|
*m::dbs::events
|
||||||
|
};
|
||||||
|
|
||||||
|
auto &column
|
||||||
|
{
|
||||||
|
dbs::event_json
|
||||||
|
};
|
||||||
|
|
||||||
|
auto it
|
||||||
|
{
|
||||||
|
column.begin()
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx::dock dock;
|
||||||
|
ctx::pool pool;
|
||||||
|
pool.min(pool_size);
|
||||||
|
size_t i(0), j(0);
|
||||||
|
for(; it; ++it)
|
||||||
|
{
|
||||||
|
std::string event{it->second};
|
||||||
|
const m::event::idx event_idx
|
||||||
|
{
|
||||||
|
byte_view<m::event::idx>(it->first)
|
||||||
|
};
|
||||||
|
|
||||||
|
pool([&txn, &dock, &i, &j, event(std::move(event)), event_idx]
|
||||||
|
{
|
||||||
|
m::dbs::write_opts wopts;
|
||||||
|
wopts.event_idx = event_idx;
|
||||||
|
m::dbs::_index_event_refs(txn, json::object{event}, wopts);
|
||||||
|
if(++j % log_interval == 0) log::info
|
||||||
|
{
|
||||||
|
m::log, "Refs builder @%zu:%zu of %lu (@idx: %lu)",
|
||||||
|
i,
|
||||||
|
j,
|
||||||
|
m::vm::current_sequence,
|
||||||
|
event_idx
|
||||||
|
};
|
||||||
|
|
||||||
|
dock.notify_one();
|
||||||
|
});
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
dock.wait([&i, &j]
|
||||||
|
{
|
||||||
|
return i == j;
|
||||||
|
});
|
||||||
|
|
||||||
|
txn();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue