mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-01 02:33:39 -07:00
global: fixes
This commit is contained in:
@@ -22,17 +22,23 @@ impl ServerRoutes for ApiRouter<AppState> {
|
||||
get_with(
|
||||
async |State(state): State<AppState>| -> axum::Json<Health> {
|
||||
let uptime = state.started_instant.elapsed();
|
||||
let tip_height = state.client.get_last_height();
|
||||
let sync = state.sync(|q| {
|
||||
let tip_height = tip_height.unwrap_or(q.indexed_height());
|
||||
q.sync_status(tip_height)
|
||||
});
|
||||
let started_at = state.started_at.to_string();
|
||||
let sync = state
|
||||
.run(move |q| {
|
||||
let tip_height = q
|
||||
.client()
|
||||
.get_last_height()
|
||||
.unwrap_or(q.indexed_height());
|
||||
Ok(q.sync_status(tip_height))
|
||||
})
|
||||
.await
|
||||
.expect("health sync task panicked");
|
||||
axum::Json(Health {
|
||||
status: Cow::Borrowed("healthy"),
|
||||
service: Cow::Borrowed("brk"),
|
||||
version: Cow::Borrowed(VERSION),
|
||||
timestamp: jiff::Timestamp::now().to_string(),
|
||||
started_at: state.started_at.to_string(),
|
||||
started_at,
|
||||
uptime_seconds: uptime.as_secs(),
|
||||
sync,
|
||||
})
|
||||
@@ -70,11 +76,10 @@ impl ServerRoutes for ApiRouter<AppState> {
|
||||
"/api/server/sync",
|
||||
get_with(
|
||||
async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| {
|
||||
let tip_height = state.client.get_last_height();
|
||||
|
||||
state
|
||||
.cached_json(&headers, CacheStrategy::Height, &uri, move |q| {
|
||||
Ok(q.sync_status(tip_height?))
|
||||
let tip_height = q.client().get_last_height()?;
|
||||
Ok(q.sync_status(tip_height))
|
||||
})
|
||||
.await
|
||||
},
|
||||
|
||||
@@ -14,7 +14,8 @@ pub enum ContentEncoding {
|
||||
|
||||
impl ContentEncoding {
|
||||
/// Negotiate the best encoding from the Accept-Encoding header.
|
||||
/// Priority: br > zstd > gzip > identity.
|
||||
/// Priority: zstd > br > gzip > identity.
|
||||
/// zstd is preferred over brotli: ~3-5x faster compression at comparable ratios.
|
||||
pub fn negotiate(headers: &HeaderMap) -> Self {
|
||||
let accept = match headers.get(header::ACCEPT_ENCODING) {
|
||||
Some(v) => v,
|
||||
@@ -29,8 +30,8 @@ impl ContentEncoding {
|
||||
for part in s.split(',') {
|
||||
let name = part.split(';').next().unwrap_or("").trim();
|
||||
match name {
|
||||
"br" => return Self::Brotli,
|
||||
"zstd" => best = Self::Zstd,
|
||||
"zstd" => return Self::Zstd,
|
||||
"br" => best = Self::Brotli,
|
||||
"gzip" if matches!(best, Self::Identity) => best = Self::Gzip,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ impl Server {
|
||||
pub fn new(query: &AsyncQuery, data_path: PathBuf, website: Website) -> Self {
|
||||
website.log();
|
||||
Self(AppState {
|
||||
client: query.client().clone(),
|
||||
query: query.clone(),
|
||||
data_path,
|
||||
website,
|
||||
|
||||
@@ -12,7 +12,6 @@ use axum::{
|
||||
http::{HeaderMap, HeaderValue, Response, Uri, header},
|
||||
};
|
||||
use brk_query::AsyncQuery;
|
||||
use brk_rpc::Client;
|
||||
use jiff::Timestamp;
|
||||
use quick_cache::sync::{Cache, GuardResult};
|
||||
use serde::Serialize;
|
||||
@@ -29,7 +28,6 @@ pub struct AppState {
|
||||
pub data_path: PathBuf,
|
||||
pub website: Website,
|
||||
pub cache: Arc<Cache<String, Bytes>>,
|
||||
pub client: Client,
|
||||
pub started_at: Timestamp,
|
||||
pub started_instant: Instant,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user