mirror of
https://github.com/matrix-construct/construct
synced 2024-06-08 13:08:56 +02:00
ircd:Ⓜ️:rooms: Add dump to file util w/ console cmd.
This commit is contained in:
parent
8d9a9eccfb
commit
cb0363f13c
|
@ -25,6 +25,9 @@ namespace ircd::m::rooms
|
|||
// tools
|
||||
size_t count(const opts & = opts_default);
|
||||
bool has(const opts & = opts_default);
|
||||
|
||||
// util
|
||||
void dump__file(const opts &, const string_view &filename);
|
||||
}
|
||||
|
||||
/// Arguments structure to rooms::for_each(). This reduces the API surface to
|
||||
|
|
|
@ -12,6 +12,53 @@ decltype(ircd::m::rooms::opts_default)
|
|||
IRCD_MODULE_EXPORT_DATA
|
||||
ircd::m::rooms::opts_default;
|
||||
|
||||
void
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::rooms::dump__file(const opts &opts,
|
||||
const string_view &filename)
|
||||
{
|
||||
const fs::fd file
|
||||
{
|
||||
filename, std::ios::out | std::ios::app
|
||||
};
|
||||
|
||||
// POSIX_FADV_DONTNEED
|
||||
fs::evict(file);
|
||||
|
||||
size_t len(0), num(0);
|
||||
for_each(opts, [&](const auto &room_id)
|
||||
{
|
||||
const const_buffer bufs[]
|
||||
{
|
||||
room_id, "\n"_sv
|
||||
};
|
||||
|
||||
len += fs::append(file, bufs);
|
||||
++num;
|
||||
|
||||
char pbuf[48];
|
||||
log::info
|
||||
{
|
||||
log, "dump[%s] rooms:%zu %s %s",
|
||||
filename,
|
||||
num,
|
||||
pretty(pbuf, iec(len)),
|
||||
string_view{room_id},
|
||||
};
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
char pbuf[48];
|
||||
log::notice
|
||||
{
|
||||
log, "dump[%s] complete rooms:%zu using %s",
|
||||
filename,
|
||||
num,
|
||||
pretty(pbuf, iec(len)),
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::rooms::has(const opts &opts)
|
||||
|
|
|
@ -8074,6 +8074,33 @@ console_cmd__rooms(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__rooms__dump(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"filename"
|
||||
}};
|
||||
|
||||
const auto filename
|
||||
{
|
||||
param.at(0)
|
||||
};
|
||||
|
||||
static conf::item<size_t>
|
||||
rooms_dump_prefetch
|
||||
{
|
||||
{ "name", "ircd.console.rooms.dump.prefetch" },
|
||||
{ "default", 16L },
|
||||
};
|
||||
|
||||
m::rooms::opts opts;
|
||||
opts.remote_only = true;
|
||||
opts.prefetch = rooms_dump_prefetch;
|
||||
m::rooms::dump__file(opts, filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__rooms__public(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue