mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
perf(app-proxy): hold the frozen snapshot by reference (#2449)
This commit is contained in:
@@ -25,7 +25,7 @@ fn serve_frozen_file(
|
|||||||
return (None, debug_header);
|
return (None, debug_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(snapshot) = &config.snapshot
|
if let Some(snapshot) = config.snapshot
|
||||||
&& let Some((bytes, content_type)) = pick(snapshot)
|
&& let Some((bytes, content_type)) = pick(snapshot)
|
||||||
{
|
{
|
||||||
let mut response = bytes.to_vec().into_response();
|
let mut response = bytes.to_vec().into_response();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub struct FrozenSnapshot {
|
|||||||
pub struct TimeFreezeConfig {
|
pub struct TimeFreezeConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub release_channel: ReleaseChannel,
|
pub release_channel: ReleaseChannel,
|
||||||
pub snapshot: Option<FrozenSnapshot>,
|
pub snapshot: Option<&'static FrozenSnapshot>,
|
||||||
pub client_exempt: bool,
|
pub client_exempt: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ pub fn load_time_freeze_config_for_index_source(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot: Option<FrozenSnapshot> = load_frozen_snapshot(release_channel);
|
let snapshot: Option<&'static FrozenSnapshot> = load_frozen_snapshot(release_channel);
|
||||||
|
|
||||||
TimeFreezeConfig {
|
TimeFreezeConfig {
|
||||||
enabled,
|
enabled,
|
||||||
@@ -98,26 +98,26 @@ pub fn load_time_freeze_config_for_index_source(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "time-freeze")]
|
#[cfg(feature = "time-freeze")]
|
||||||
fn load_frozen_snapshot(release_channel: ReleaseChannel) -> Option<FrozenSnapshot> {
|
fn load_frozen_snapshot(release_channel: ReleaseChannel) -> Option<&'static FrozenSnapshot> {
|
||||||
match release_channel {
|
match release_channel {
|
||||||
ReleaseChannel::Stable => Some(crate::frozen_snapshots::STABLE_SNAPSHOT.clone()),
|
ReleaseChannel::Stable => Some(&crate::frozen_snapshots::STABLE_SNAPSHOT),
|
||||||
ReleaseChannel::Canary => None,
|
ReleaseChannel::Canary => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "time-freeze"))]
|
#[cfg(not(feature = "time-freeze"))]
|
||||||
fn load_frozen_snapshot(_release_channel: ReleaseChannel) -> Option<FrozenSnapshot> {
|
fn load_frozen_snapshot(_release_channel: ReleaseChannel) -> Option<&'static FrozenSnapshot> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn should_serve_frozen(config: &TimeFreezeConfig) -> Option<&FrozenSnapshot> {
|
pub fn should_serve_frozen(config: &TimeFreezeConfig) -> Option<&'static FrozenSnapshot> {
|
||||||
if !config.enabled {
|
if !config.enabled {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if config.client_exempt {
|
if config.client_exempt {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
config.snapshot.as_ref()
|
config.snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn describe_decision(config: &TimeFreezeConfig) -> TimeFreezeDebug {
|
pub fn describe_decision(config: &TimeFreezeConfig) -> TimeFreezeDebug {
|
||||||
@@ -276,6 +276,7 @@ pub fn format_debug_header(debug: &TimeFreezeDebug) -> String {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use axum::http::{HeaderMap, HeaderValue};
|
use axum::http::{HeaderMap, HeaderValue};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
#[cfg(feature = "time-freeze")]
|
#[cfg(feature = "time-freeze")]
|
||||||
#[test]
|
#[test]
|
||||||
@@ -361,17 +362,19 @@ mod tests {
|
|||||||
assert!(debug.snapshot_sha.is_none());
|
assert!(debug.snapshot_sha.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TEST_SNAPSHOT: LazyLock<FrozenSnapshot> = LazyLock::new(|| FrozenSnapshot {
|
||||||
|
sha: "deadbeef".to_owned(),
|
||||||
|
index_html: vec![],
|
||||||
|
sw_js: vec![],
|
||||||
|
version_json: vec![],
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn describe_decision_frozen() {
|
fn describe_decision_frozen() {
|
||||||
let config = TimeFreezeConfig {
|
let config = TimeFreezeConfig {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
release_channel: ReleaseChannel::Stable,
|
release_channel: ReleaseChannel::Stable,
|
||||||
snapshot: Some(FrozenSnapshot {
|
snapshot: Some(&TEST_SNAPSHOT),
|
||||||
sha: "deadbeef".to_owned(),
|
|
||||||
index_html: vec![],
|
|
||||||
sw_js: vec![],
|
|
||||||
version_json: vec![],
|
|
||||||
}),
|
|
||||||
client_exempt: false,
|
client_exempt: false,
|
||||||
};
|
};
|
||||||
let debug = describe_decision(&config);
|
let debug = describe_decision(&config);
|
||||||
|
|||||||
Reference in New Issue
Block a user