From 26b126d1fbcbec5fcf7b6fc6068fd787295ec81c Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Wed, 1 Apr 2026 21:23:07 +0300 Subject: [PATCH] [lib,api] return account count when querying host status --- src/api/xrpc/get_host_status.rs | 2 +- src/api/xrpc/list_hosts.rs | 2 +- src/control/mod.rs | 12 ++++++++++++ src/db/mod.rs | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/api/xrpc/get_host_status.rs b/src/api/xrpc/get_host_status.rs index ad1ea01..2f19ee9 100644 --- a/src/api/xrpc/get_host_status.rs +++ b/src/api/xrpc/get_host_status.rs @@ -20,7 +20,7 @@ pub async fn handle( }; Ok(Json(GetHostStatusOutput { - account_count: None, + account_count: Some(host.account_count as i64), hostname: CowStr::Owned(host.name), seq: Some(host.seq), status: None, diff --git a/src/api/xrpc/list_hosts.rs b/src/api/xrpc/list_hosts.rs index 6914216..64193a9 100644 --- a/src/api/xrpc/list_hosts.rs +++ b/src/api/xrpc/list_hosts.rs @@ -25,7 +25,7 @@ pub async fn handle( hostname: CowStr::Owned(h.name), seq: Some(h.seq), status: None, - account_count: None, + account_count: Some(h.account_count as i64), extra_data: None, }) .collect(), diff --git a/src/control/mod.rs b/src/control/mod.rs index 255fa47..29102eb 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -57,8 +57,12 @@ use stream::relay_stream_thread; /// infromation about a host hydrant is consuming from. pub struct Host { + /// hostname of the host. pub name: SmolStr, + /// latest seq hydrant has processed from this host. pub seq: i64, + /// the amount of accounts hydrant has seen from this host. + pub account_count: u64, } /// an event emitted by the hydrant event stream. @@ -789,10 +793,14 @@ impl Hydrant { .into_diagnostic() .wrap_err("cursor value is not 8 bytes")?, ); + let account_count = state + .db + .get_count_sync(&keys::pds_account_count_key(&hostname)); Ok(Some(Host { name: hostname.into(), seq, + account_count, })) }) .await @@ -839,9 +847,13 @@ impl Hydrant { .into_diagnostic() .wrap_err("cursor value is not 8 bytes")?, ); + let account_count = state + .db + .get_count_sync(&keys::pds_account_count_key(hostname)); hosts.push(Host { name: hostname.into(), seq, + account_count, }); } diff --git a/src/db/mod.rs b/src/db/mod.rs index cc68e54..51441d9 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -747,6 +747,10 @@ impl Db { .await .unwrap_or(0) } + + pub fn get_count_sync(&self, key: &str) -> u64 { + self.counts_map.read_sync(key, |_, v| *v).unwrap_or(0) + } } #[cfg(feature = "indexer")] -- 2.51.2