From 9bc53d5cd57aec2da7d91d0cac133aa8ce8bd27a Mon Sep 17 00:00:00 2001 From: 4cuck <40539855+4cuck@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:26:23 +0200 Subject: [PATCH] fixup sorting --- scanner/src/cache_update.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scanner/src/cache_update.rs b/scanner/src/cache_update.rs index cee6995..93c47a7 100644 --- a/scanner/src/cache_update.rs +++ b/scanner/src/cache_update.rs @@ -1,3 +1,4 @@ +use std::cmp; // SPDX-License-Identifier: AGPL-3.0-only use std::collections::HashMap; @@ -162,7 +163,26 @@ impl Scanner { recent_checks: self.query_latest_health_checks(22, host.id).await?, }) } - host_statistics.sort_unstable_by_key(|k| k.points); + host_statistics.sort_unstable_by(|a,b| { + if a.points > 0 { + match a.points.cmp(&b.points) { + cmp::Ordering::Equal => a.healthy_percentage_overall.cmp(&b.healthy_percentage_overall), + v => v, + } + } else { + let cmp_v: cmp::Ordering = b.__show_last_seen.cmp(&a.__show_last_seen); + if cmp_v.is_ne() { + cmp_v + } else { + match (a.last_healthy,b.last_healthy) { + (Some(a),Some(b)) => a.cmp(&b), + (Some(_),None) => cmp::Ordering::Greater, + (None,Some(_)) => cmp::Ordering::Less, + (None,None) => cmp::Ordering::Equal, + } + } + } + }); host_statistics.reverse(); Ok(CacheData { hosts: host_statistics,