From 41d00321d59b703e98fe447bd2e7af2782259583 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 24 Jun 2026 13:09:35 +0900 Subject: [PATCH] ruptime: fix `--all` flag behaviour, move filtering to server --- src/bin/ruptime.rs | 14 +++----------- src/server/varlink_api.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/bin/ruptime.rs b/src/bin/ruptime.rs index b30e598..a0938f9 100644 --- a/src/bin/ruptime.rs +++ b/src/bin/ruptime.rs @@ -96,7 +96,7 @@ async fn main() -> anyhow::Result<()> { // } } else { for entry in &reply { - let line = old_format_machine_entry(args.all, entry); + let line = old_format_machine_entry(entry); println!("{}", line); } } @@ -138,7 +138,7 @@ fn sort_entries( }); } -fn old_format_machine_entry(all: bool, entry: &WhodStatusUpdate) -> String { +fn old_format_machine_entry(entry: &WhodStatusUpdate) -> String { let time_since_last_ping = Utc::now() - entry.sendtime; let is_up = time_since_last_ping <= Duration::minutes(11); @@ -155,15 +155,7 @@ fn old_format_machine_entry(all: bool, entry: &WhodStatusUpdate) -> String { format!(" {:2}:{:02}", hours, minutes) }; - let user_count = if all { - entry.users.len() - } else { - entry - .users - .iter() - .filter(|user| user.idle_time < Duration::hours(1)) - .count() - }; + let user_count = entry.users.len(); format!( "{:<12.12} {} {}, {:4} user{} load {:>4.2}, {:>4.2}, {:>4.2}", diff --git a/src/server/varlink_api.rs b/src/server/varlink_api.rs index 04ad98e..fdd8c64 100644 --- a/src/server/varlink_api.rs +++ b/src/server/varlink_api.rs @@ -182,12 +182,18 @@ impl VarlinkRoowhoo2ClientServer { async fn handle_ruptime_request(&self, all: bool) -> VarlinkRuptimeResponse { tracing::debug!(all, "Handling Ruptime request"); let store = self.whod_status_store.read().await; + store .values() - .filter(|status_update| { - all || chrono::Utc::now() - status_update.sendtime < chrono::Duration::hours(1) - }) .cloned() + .map(|mut status_update| { + if !all { + status_update + .users + .retain(|user| user.idle_time < chrono::Duration::hours(1)); + } + status_update + }) .collect() }