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

+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() {