💄 de-dupe unregistered servers list

main
_ 2021-05-02 18:01:02 +00:00
parent 810a34463c
commit 62248aca53
1 changed files with 19 additions and 5 deletions

View File

@ -22,6 +22,7 @@
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::HashSet,
convert::Infallible, convert::Infallible,
net::SocketAddr, net::SocketAddr,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -358,20 +359,33 @@ async fn handle_unregistered_servers_internal (state: &Arc <Relay>)
let now = Utc::now (); let now = Utc::now ();
let server_list = state.unregistered_servers.to_vec ().await; let server_list = state.unregistered_servers.to_vec ().await;
let mut seen_tripcodes = HashSet::new ();
let unregistered_servers = server_list.into_iter () let unregistered_servers = server_list.into_iter ()
.map (|x| { .rev ()
.filter_map (|x| {
let last_seen = match pretty_print_last_seen (now, x.seen) { let last_seen = match pretty_print_last_seen (now, x.seen) {
Negative => "Error (negative time)".into (), Negative => "Error (negative time)".into (),
Connected => "Recently".into (), Connected => "Recently".into (),
Description (s) => s, Description (s) => s,
}; };
UnregisteredServer { let t = (x.name, x.tripcode);
name: x.name,
tripcode: base64::encode (x.tripcode.as_bytes ()), if seen_tripcodes.contains (&t) {
last_seen, return None;
} }
seen_tripcodes.insert (t.clone ());
let (name, tripcode) = t;
let tripcode = base64::encode (tripcode.as_bytes ());
Some (UnregisteredServer {
name,
tripcode,
last_seen,
})
}).collect (); }).collect ();
UnregisteredServerListPage { UnregisteredServerListPage {