Merge branch 'master' into pr/atty303/1948

This commit is contained in:
Evan Almloff committed 2024-02-19 08:35:31 -06:00
commit c4a4a31eec
78 files changed
+1277 -4465

No files matched your search

+6 -5
View File
@@ -15,11 +15,11 @@ generational-box = { workspace = true }
askama_escape = "0.10.3"
thiserror = "1.0.23"
rustc-hash = "1.1.0"
lru = "0.10.0"
lru = { workspace = true }
tracing = { workspace = true }
http = "0.2.9"
async-trait = "0.1.58"
serde_json = { version = "1.0" }
http = { workspace = true }
async-trait = { workspace = true }
serde_json = { workspace = true }
chrono = { verison = "0.4.34", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
@@ -30,6 +30,8 @@ tokio = { version = "1.28", features = ["fs", "io-util"], optional = true }
[dev-dependencies]
dioxus = { workspace = true }
dioxus-signals = { workspace = true }
tracing = { workspace = true }
fern = { version = "0.6.0", features = ["colored"] }
anyhow = "1.0"
@@ -37,7 +39,6 @@ argh = "0.1.4"
serde = "1.0.120"
serde_json = "1.0.61"
fs_extra = "1.2.0"
dioxus-signals = { workspace = true }
[features]
default = []
+1
View File
@@ -103,6 +103,7 @@ impl ValidCachedPath {
})
}
#[cfg(not(target_arch = "wasm32"))]
pub fn freshness(&self, max_age: Option<std::time::Duration>) -> Option<RenderFreshness> {
let age = self.timestamp.elapsed().ok()?.as_secs();
let max_age = max_age.map(|max_age| max_age.as_secs());
+6 -3
View File
@@ -10,13 +10,12 @@ use rustc_hash::FxHasher;
use std::{
future::Future,
hash::BuildHasherDefault,
io::Write,
ops::{Deref, DerefMut},
path::PathBuf,
pin::Pin,
time::{Duration, SystemTime},
};
use tokio::io::{AsyncWrite, AsyncWriteExt, BufReader};
use tokio::io::{AsyncWrite, AsyncWriteExt};
pub use crate::fs_cache::*;
pub use crate::incremental_cfg::*;
@@ -67,6 +66,7 @@ impl IncrementalRenderer {
let _ = std::fs::remove_dir_all(&self.static_dir);
}
#[cfg(not(target_arch = "wasm32"))]
fn track_timestamps(&self) -> bool {
self.invalidate_after.is_some()
}
@@ -102,6 +102,7 @@ impl IncrementalRenderer {
) -> Result<RenderFreshness, IncrementalRendererError> {
#[cfg(not(target_arch = "wasm32"))]
{
use std::io::Write;
let file_path = self.route_as_path(&route);
if let Some(parent) = file_path.parent() {
if !parent.exists() {
@@ -122,6 +123,7 @@ impl IncrementalRenderer {
}
}
#[cfg(not(target_arch = "wasm32"))]
fn promote_memory_cache<K: AsRef<str>>(&mut self, route: K) {
if let Some(cache) = self.memory_cache.as_mut() {
cache.promote(route.as_ref())
@@ -160,7 +162,7 @@ impl IncrementalRenderer {
if let Some(file_path) = self.find_file(&route) {
if let Some(freshness) = file_path.freshness(self.invalidate_after) {
if let Ok(file) = tokio::fs::File::open(file_path.full_path).await {
let mut file = BufReader::new(file);
let mut file = tokio::io::BufReader::new(file);
tokio::io::copy_buf(&mut file, output).await?;
tracing::trace!("file cache hit {:?}", route);
self.promote_memory_cache(&route);
@@ -229,6 +231,7 @@ impl IncrementalRenderer {
}
}
#[cfg(not(target_arch = "wasm32"))]
fn route_as_path(&self, route: &str) -> PathBuf {
let mut file_path = (self.map_path)(route);
if self.track_timestamps() {