diff --git a/src/main.rs b/src/main.rs index 7296652..c357b81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,37 +83,36 @@ async fn main() -> eyre::Result<()> { .instrument(info_span!("custom_template_watcher")), ); - let posts: Arc = match config.engine { - Engine::Markdown => { - let cache = if config.cache.enable { - if config.cache.persistence && tokio::fs::try_exists(&config.cache.file).await? { - info!("loading cache from file"); - let mut cache = load_cache(&config.cache).await.unwrap_or_else(|err| { - error!("failed to load cache: {}", err); - info!("using empty cache"); - Default::default() - }); + let cache = if config.cache.enable { + if config.cache.persistence && tokio::fs::try_exists(&config.cache.file).await? { + info!("loading cache from file"); + let mut cache = load_cache(&config.cache).await.unwrap_or_else(|err| { + error!("failed to load cache: {}", err); + info!("using empty cache"); + Default::default() + }); - if cache.version() < CACHE_VERSION { - warn!("cache version changed, clearing cache"); - cache = Default::default(); - }; + if cache.version() < CACHE_VERSION { + warn!("cache version changed, clearing cache"); + cache = Default::default(); + }; - Some(cache) - } else { - Some(Default::default()) - } - } else { - None - } - .map(|cache| CacheGuard::new(cache, config.cache.clone())) - .map(Arc::new); - - Arc::new(MarkdownPosts::new(Arc::clone(&config), cache.clone()).await?) + Some(cache) + } else { + Some(Default::default()) } + } else { + None + } + .map(|cache| CacheGuard::new(cache, config.cache.clone())) + .map(Arc::new); + + let posts: Arc = match config.engine { + Engine::Markdown => Arc::new(MarkdownPosts::new(Arc::clone(&config), cache.clone()).await?), Engine::Blag => Arc::new(Blag::new( config.dirs.posts.clone().into(), config.blag.bin.clone().into(), + cache.clone(), )), }; diff --git a/src/post/blag.rs b/src/post/blag.rs index 196452a..59b34d9 100644 --- a/src/post/blag.rs +++ b/src/post/blag.rs @@ -16,16 +16,24 @@ use tracing::{debug, error}; use crate::error::PostError; use crate::post::Filter; +use super::cache::CacheGuard; use super::{ApplyFilters, PostManager, PostMetadata, RenderStats, ReturnedPost}; pub struct Blag { root: Arc, blag_bin: Arc, + _cache: Option>, + _fastblag: bool, } impl Blag { - pub fn new(root: Arc, blag_bin: Arc) -> Blag { - Self { root, blag_bin } + pub fn new(root: Arc, blag_bin: Arc, _cache: Option>) -> Blag { + Self { + root, + blag_bin, + _cache, + _fastblag: false, + } } } @@ -94,6 +102,7 @@ impl PostManager for Blag { name: &str, _query: &HashMap, ) -> Result { + let start = Instant::now(); let mut path = self.root.join(name); if name.ends_with(".sh") { @@ -117,7 +126,6 @@ impl PostManager for Blag { path.add_extension("sh"); } - let start = Instant::now(); let stat = tokio::fs::metadata(&path) .await .map_err(|err| match err.kind() { @@ -146,6 +154,9 @@ impl PostManager for Blag { let mut meta: PostMetadata = serde_json::from_str(&buf)?; meta.name = name.to_string(); + let parsed = start.elapsed(); + + let rendering = Instant::now(); buf.clear(); reader.read_to_string(&mut buf).await?; @@ -157,12 +168,17 @@ impl PostManager for Blag { return Err(PostError::RenderError(exit_status.to_string())); } - let elapsed = start.elapsed(); + let rendered = rendering.elapsed(); + let total = start.elapsed(); Ok(ReturnedPost::Rendered( meta, buf, - RenderStats::ParsedAndRendered(elapsed, elapsed, elapsed), + RenderStats::Rendered { + parsed, + rendered, + total, + }, )) } diff --git a/src/post/markdown_posts.rs b/src/post/markdown_posts.rs index 0f7f31e..cda4010 100644 --- a/src/post/markdown_posts.rs +++ b/src/post/markdown_posts.rs @@ -275,7 +275,11 @@ impl PostManager for MarkdownPosts { Ok(ReturnedPost::Rendered( metadata, rendered, - RenderStats::ParsedAndRendered(start.elapsed(), stats.0, stats.1), + RenderStats::Rendered { + total: start.elapsed(), + parsed: stats.0, + rendered: stats.1, + }, )) } } diff --git a/src/post/mod.rs b/src/post/mod.rs index 1e51590..2b40fb3 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -29,10 +29,16 @@ pub struct PostMetadata { } #[derive(Serialize, Debug)] +#[allow(unused)] pub enum RenderStats { Cached(Duration), - // format: Total, Parsed in, Rendered in - ParsedAndRendered(Duration, Duration, Duration), + Rendered { + total: Duration, + parsed: Duration, + rendered: Duration, + }, + Fetched(Duration), + Unknown, } #[allow(clippy::large_enum_variant)] // Raw will be returned very rarely diff --git a/templates/footer.hbs b/templates/footer.hbs index 30ef8ad..11ef473 100644 --- a/templates/footer.hbs +++ b/templates/footer.hbs @@ -1,18 +1,22 @@ -running {{bingus_info.name}} v{{bingus_info.version}} +running +{{bingus_info.name}} +v{{bingus_info.version}} {{#if rendered_in}} - - + - {{/if}} {{#each rendered_in}} - {{#if (eq @key "ParsedAndRendered")}} - parsed + {{#if (eq @key "Rendered")}} + parsed meta and - rendered + rendered in - {{duration this.0}} - + {{duration this.total}} {{else if (eq @key "Cached")}} retrieved from cache in {{duration this}} + {{else if (eq @key "Fetched")}} + fetched in + {{duration this}} {{/if}} {{/each}} {{#if raw_name}}