0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:room: Start a room statistics interface.

This commit is contained in:
Jason Volk 2019-02-25 16:28:53 -08:00
parent 6f7fc0a837
commit f3d4e27b24
6 changed files with 165 additions and 0 deletions

View file

@ -83,3 +83,4 @@ namespace ircd::m
#include "room/head.h"
#include "room/auth.h"
#include "room/power.h"
#include "room/stats.h"

View file

@ -37,6 +37,7 @@ struct ircd::m::room
struct head;
struct auth;
struct power;
struct stats;
using id = m::id::room;
using alias = m::id::room_alias;

View file

@ -0,0 +1,21 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_ROOM_STATS_H
struct ircd::m::room::stats
{
static size_t bytes_json_compressed(const m::room &);
static size_t bytes_json(const m::room &);
static size_t bytes_total_compressed(const m::room &);
static size_t bytes_total(const m::room &);
};

View file

@ -2573,3 +2573,59 @@ const
closure(power_event_content);
return !empty(power_event_content);
}
//
// room::stats
//
size_t
ircd::m::room::stats::bytes_json_compressed(const m::room &room)
{
using prototype = size_t (const m::room &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::stats::bytes_json_compressed"
};
return call(room);
}
size_t
ircd::m::room::stats::bytes_json(const m::room &room)
{
using prototype = size_t (const m::room &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::stats::bytes_json"
};
return call(room);
}
size_t
ircd::m::room::stats::bytes_total_compressed(const m::room &room)
{
using prototype = size_t (const m::room &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::stats::bytes_total_compressed"
};
return call(room);
}
size_t
ircd::m::room::stats::bytes_total(const m::room &room)
{
using prototype = size_t (const m::room &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::stats::bytes_total"
};
return call(room);
}

View file

@ -8371,6 +8371,31 @@ console_cmd__room__auth(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__stats(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id",
}};
const auto &room_id
{
m::room_id(param.at("room_id"))
};
const size_t bytes_json
{
m::room::stats::bytes_json(room_id)
};
out << "JSON bytes: "
<< pretty(iec(bytes_json))
<< std::endl;
return true;
}
//
// user
//

View file

@ -860,3 +860,64 @@ ircd::m::room::auth::for_each(const auth &a,
return true;
}
size_t
IRCD_MODULE_EXPORT
__attribute__((noreturn))
ircd::m::room::stats::bytes_total(const m::room &room)
{
throw m::UNSUPPORTED
{
"Not yet implemented."
};
}
size_t
IRCD_MODULE_EXPORT
__attribute__((noreturn))
ircd::m::room::stats::bytes_total_compressed(const m::room &room)
{
throw m::UNSUPPORTED
{
"Not yet implemented."
};
}
size_t
IRCD_MODULE_EXPORT
ircd::m::room::stats::bytes_json(const m::room &room)
{
size_t ret(0);
for(m::room::messages it(room); it; --it)
{
const m::event::idx &event_idx
{
it.event_idx()
};
const byte_view<string_view> key
{
event_idx
};
static const db::gopts gopts
{
db::get::NO_CACHE
};
ret += db::bytes_value(m::dbs::event_json, key, gopts);
}
return ret;
}
size_t
IRCD_MODULE_EXPORT
__attribute__((noreturn))
ircd::m::room::stats::bytes_json_compressed(const m::room &room)
{
throw m::UNSUPPORTED
{
"Not yet implemented."
};
}