Exclude admins from collected metrics

This commit is contained in:
Antonio Scandurra 2022-06-14 16:26:00 +02:00
parent 226fa6e3be
commit 6d93a41f40
2 changed files with 12 additions and 6 deletions

View file

@ -329,7 +329,7 @@ impl Server {
{
let mut store = this.store_mut().await;
store.add_connection(connection_id, user_id);
store.add_connection(connection_id, user_id, user.admin);
this.peer.send(connection_id, store.build_initial_contacts_update(contacts))?;
if let Some((code, count)) = invite_code {

View file

@ -25,6 +25,7 @@ pub struct Store {
#[derive(Serialize)]
struct ConnectionState {
user_id: UserId,
admin: bool,
projects: HashSet<u64>,
requested_projects: HashSet<u64>,
channels: HashSet<ChannelId>,
@ -88,13 +89,17 @@ pub struct Metrics {
impl Store {
pub fn metrics(&self) -> Metrics {
let connections = self.connections.len();
let connections = self.connections.values().filter(|c| !c.admin).count();
let mut registered_projects = 0;
let mut shared_projects = 0;
for project in self.projects.values() {
registered_projects += 1;
if !project.guests.is_empty() {
shared_projects += 1;
if let Some(connection) = self.connections.get(&project.host_connection_id) {
if !connection.admin {
registered_projects += 1;
if !project.guests.is_empty() {
shared_projects += 1;
}
}
}
}
@ -106,11 +111,12 @@ impl Store {
}
#[instrument(skip(self))]
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId, admin: bool) {
self.connections.insert(
connection_id,
ConnectionState {
user_id,
admin,
projects: Default::default(),
requested_projects: Default::default(),
channels: Default::default(),