0
0
Fork 0
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:
Jason Volk 2020-02-28 18:03:05 -08:00
parent 8d9a9eccfb
commit cb0363f13c
3 changed files with 77 additions and 0 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)
{