💄 de-dupe unregistered servers list
parent
810a34463c
commit
62248aca53
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue