fix: app cache and other issues (#5460)
* fixes * #[serde(untagged)] my BEHATED (still kinda broken) * remove unused hasContent ref * clean up code in fetch instance * ping 3 times for average latency * fix: pinging to be more accurate TCP_NODELAY — Set on the TCP stream right after connect, preventing Nagle's algorithm from buffering the small ping packet (could save up to ~40ms) Instant over Utc::now() — Switched to monotonic std::time::Instant for timing, which is more precise and designed for measuring elapsed time (still using chrono just for the ping magic value) * delete useFetch util and just use native fetch * rename worlds until functions for more clarity * fix lint * fix cache.rs logic * make backend ping use both impls * Add optional timeout to server ping * fix gallery appearing in nav with no items * remove EU countries and add EU option for server country * add uk to europe --------- Co-authored-by: aecsocket <aecsocket@tutanota.com>
This commit is contained in:
@@ -69,7 +69,7 @@ pub async fn get_server_status(
|
||||
mod modern {
|
||||
use super::ServerStatus;
|
||||
use crate::ErrorKind;
|
||||
use chrono::Utc;
|
||||
use std::time::Instant;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::{TcpStream, ToSocketAddrs};
|
||||
|
||||
@@ -79,6 +79,7 @@ mod modern {
|
||||
protocol_version: Option<u32>,
|
||||
) -> crate::Result<ServerStatus> {
|
||||
let mut stream = TcpStream::connect(address).await?;
|
||||
stream.set_nodelay(true)?;
|
||||
handshake(&mut stream, original_address, protocol_version).await?;
|
||||
let mut result = status_body(&mut stream).await?;
|
||||
result.ping = ping(&mut stream).await.ok();
|
||||
@@ -155,9 +156,9 @@ mod modern {
|
||||
}
|
||||
|
||||
async fn ping(stream: &mut TcpStream) -> crate::Result<i64> {
|
||||
let start_time = Utc::now();
|
||||
let ping_magic = start_time.timestamp_millis();
|
||||
let ping_magic = chrono::Utc::now().timestamp_millis();
|
||||
|
||||
let start_time = Instant::now();
|
||||
stream.write_all(&[0x09, 0x01]).await?;
|
||||
stream.write_i64(ping_magic).await?;
|
||||
stream.flush().await?;
|
||||
@@ -172,8 +173,7 @@ mod modern {
|
||||
.into());
|
||||
}
|
||||
|
||||
let response_time = Utc::now();
|
||||
Ok((response_time - start_time).num_milliseconds())
|
||||
Ok(start_time.elapsed().as_millis() as i64)
|
||||
}
|
||||
|
||||
mod varint {
|
||||
|
||||
Reference in New Issue
Block a user