fix: hopefully fixed the background task progress situation
This commit is contained in:
@@ -161,6 +161,7 @@ fn generate_starter_site_with_progress_mode(
|
||||
posts,
|
||||
section,
|
||||
force,
|
||||
&|_| {},
|
||||
&mut on_page,
|
||||
|| false,
|
||||
)?);
|
||||
@@ -189,6 +190,7 @@ pub fn render_site_section_with_progress(
|
||||
posts: &[PublishedPostSource],
|
||||
section: GenerationSection,
|
||||
mut on_page: impl FnMut(usize, usize, &str),
|
||||
on_page_rendered: impl Fn(&str) + Sync,
|
||||
mut is_cancelled: impl FnMut() -> bool,
|
||||
) -> EngineResult<GenerationReport> {
|
||||
render_site_section_with_progress_mode(
|
||||
@@ -199,6 +201,7 @@ pub fn render_site_section_with_progress(
|
||||
posts,
|
||||
section,
|
||||
false,
|
||||
&on_page_rendered,
|
||||
&mut on_page,
|
||||
&mut is_cancelled,
|
||||
)
|
||||
@@ -216,6 +219,7 @@ pub fn render_site_section_forced_with_progress(
|
||||
posts: &[PublishedPostSource],
|
||||
section: GenerationSection,
|
||||
mut on_page: impl FnMut(usize, usize, &str),
|
||||
on_page_rendered: impl Fn(&str) + Sync,
|
||||
mut is_cancelled: impl FnMut() -> bool,
|
||||
) -> EngineResult<GenerationReport> {
|
||||
render_site_section_with_progress_mode(
|
||||
@@ -226,6 +230,7 @@ pub fn render_site_section_forced_with_progress(
|
||||
posts,
|
||||
section,
|
||||
true,
|
||||
&on_page_rendered,
|
||||
&mut on_page,
|
||||
&mut is_cancelled,
|
||||
)
|
||||
@@ -243,6 +248,7 @@ fn render_site_section_with_progress_mode(
|
||||
posts: &[PublishedPostSource],
|
||||
section: GenerationSection,
|
||||
force: bool,
|
||||
on_page_rendered: &(dyn Fn(&str) + Sync),
|
||||
mut on_page: impl FnMut(usize, usize, &str),
|
||||
mut is_cancelled: impl FnMut() -> bool,
|
||||
) -> EngineResult<GenerationReport> {
|
||||
@@ -261,6 +267,7 @@ fn render_site_section_with_progress_mode(
|
||||
metadata,
|
||||
&input_posts,
|
||||
section,
|
||||
on_page_rendered,
|
||||
)
|
||||
.map_err(|error| EngineError::Parse(error.to_string()))?;
|
||||
let mut report = GenerationReport::default();
|
||||
@@ -361,6 +368,7 @@ pub fn apply_validation_sections(
|
||||
validation,
|
||||
*section,
|
||||
|_current, _total, _url| {},
|
||||
|_| {},
|
||||
|| false,
|
||||
)?);
|
||||
}
|
||||
@@ -384,6 +392,7 @@ pub fn apply_validation_section_with_progress(
|
||||
validation: &SiteValidationReport,
|
||||
section: GenerationSection,
|
||||
mut on_page: impl FnMut(usize, usize, &str),
|
||||
on_page_rendered: impl Fn(&str) + Sync,
|
||||
mut is_cancelled: impl FnMut() -> bool,
|
||||
) -> EngineResult<GenerationReport> {
|
||||
if is_cancelled() {
|
||||
@@ -414,6 +423,7 @@ pub fn apply_validation_section_with_progress(
|
||||
metadata,
|
||||
&input_posts,
|
||||
section,
|
||||
&on_page_rendered,
|
||||
)
|
||||
} else {
|
||||
build_targeted_site_section_render_artifacts(
|
||||
@@ -424,6 +434,7 @@ pub fn apply_validation_section_with_progress(
|
||||
&input_posts,
|
||||
section,
|
||||
&requested,
|
||||
&on_page_rendered,
|
||||
)
|
||||
}
|
||||
.map_err(|error| EngineError::Parse(error.to_string()))?;
|
||||
|
||||
@@ -23,7 +23,7 @@ pub use routes::{
|
||||
pub use site::{
|
||||
PagefindDocument, PreviewRenderResult, SitePage, SiteRenderArtifacts, build_preview_response,
|
||||
build_site_render_artifacts, build_site_route_manifest, build_site_section_render_artifacts,
|
||||
build_targeted_site_section_render_artifacts,
|
||||
build_targeted_site_section_render_artifacts, estimate_site_render_pages,
|
||||
};
|
||||
pub use template_lookup::{
|
||||
RenderCategorySettings, RenderTemplateLookup, TemplateLookupError, resolve_post_template,
|
||||
|
||||
@@ -119,6 +119,7 @@ pub fn build_site_render_artifacts(
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
&|_| {},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -188,6 +189,7 @@ pub fn build_site_section_render_artifacts(
|
||||
metadata: &ProjectMetadata,
|
||||
published_posts: &[(Post, String)],
|
||||
section: GenerationSection,
|
||||
on_page_rendered: &(dyn Fn(&str) + Sync),
|
||||
) -> Result<SiteRenderArtifacts, Box<dyn Error + Send + Sync>> {
|
||||
build_site_render_artifacts_with_mode(
|
||||
conn,
|
||||
@@ -198,6 +200,7 @@ pub fn build_site_section_render_artifacts(
|
||||
false,
|
||||
Some(section),
|
||||
None,
|
||||
on_page_rendered,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -209,6 +212,7 @@ pub fn build_targeted_site_section_render_artifacts(
|
||||
published_posts: &[(Post, String)],
|
||||
section: GenerationSection,
|
||||
requested_paths: &HashSet<String>,
|
||||
on_page_rendered: &(dyn Fn(&str) + Sync),
|
||||
) -> Result<SiteRenderArtifacts, Box<dyn Error + Send + Sync>> {
|
||||
build_site_render_artifacts_with_mode(
|
||||
conn,
|
||||
@@ -219,9 +223,28 @@ pub fn build_targeted_site_section_render_artifacts(
|
||||
false,
|
||||
Some(section),
|
||||
Some(requested_paths),
|
||||
on_page_rendered,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn estimate_site_render_pages(
|
||||
data_dir: &Path,
|
||||
metadata: &ProjectMetadata,
|
||||
published_posts: &[Post],
|
||||
) -> Result<HashMap<GenerationSection, usize>, Box<dyn Error + Send + Sync>> {
|
||||
let mut estimates = GenerationSection::ALL
|
||||
.into_iter()
|
||||
.map(|section| (section, 0))
|
||||
.collect::<HashMap<_, _>>();
|
||||
for page in build_site_route_manifest(data_dir, metadata, published_posts)? {
|
||||
if let Some(section) = classify_generated_path(&page.relative_path, metadata) {
|
||||
*estimates.get_mut(§ion).unwrap() += 1;
|
||||
}
|
||||
}
|
||||
*estimates.get_mut(&GenerationSection::Core).unwrap() += render_languages(metadata).len();
|
||||
Ok(estimates)
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "the shared renderer accepts optional section and path filters"
|
||||
@@ -235,6 +258,7 @@ fn build_site_render_artifacts_with_mode(
|
||||
is_preview: bool,
|
||||
section: Option<GenerationSection>,
|
||||
requested_paths: Option<&HashSet<String>>,
|
||||
on_page_rendered: &(dyn Fn(&str) + Sync),
|
||||
) -> Result<SiteRenderArtifacts, Box<dyn Error + Send + Sync>> {
|
||||
let bundle = load_template_bundle(conn, data_dir, project_id)?;
|
||||
let main_language = main_language(metadata).to_string();
|
||||
@@ -316,11 +340,14 @@ fn build_site_render_artifacts_with_mode(
|
||||
&bundle,
|
||||
is_preview,
|
||||
)
|
||||
.map(|html| SitePage {
|
||||
language: language.clone(),
|
||||
relative_path: route.relative_path.clone(),
|
||||
url_path: route.url_path.clone(),
|
||||
html,
|
||||
.map(|html| {
|
||||
on_page_rendered(&route.url_path);
|
||||
SitePage {
|
||||
language: language.clone(),
|
||||
relative_path: route.relative_path.clone(),
|
||||
url_path: route.url_path.clone(),
|
||||
html,
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
@@ -343,17 +370,14 @@ fn build_site_render_artifacts_with_mode(
|
||||
};
|
||||
if requested_paths.is_none_or(|requested| requested.contains(&relative_path)) {
|
||||
let url_path = format!("/{}", relative_path.trim_end_matches(".html"));
|
||||
let html =
|
||||
render_not_found_route(&bundle, metadata, &language, &url_path, &menu_items)?;
|
||||
on_page_rendered(&url_path);
|
||||
artifacts.pages.push(SitePage {
|
||||
language: language.clone(),
|
||||
relative_path,
|
||||
url_path: url_path.clone(),
|
||||
html: render_not_found_route(
|
||||
&bundle,
|
||||
metadata,
|
||||
&language,
|
||||
&url_path,
|
||||
&menu_items,
|
||||
)?,
|
||||
html,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -410,6 +434,7 @@ fn build_site_render_artifacts_with_mode(
|
||||
&bundle,
|
||||
is_preview,
|
||||
)?;
|
||||
on_page_rendered(&url_path);
|
||||
artifacts.pagefind_documents.push(PagefindDocument {
|
||||
language: language.clone(),
|
||||
relative_path: relative_path.clone(),
|
||||
@@ -448,6 +473,7 @@ pub fn build_preview_response(
|
||||
true,
|
||||
None,
|
||||
Some(&requested_paths),
|
||||
&|_| {},
|
||||
)?;
|
||||
if let Some(page) = artifacts
|
||||
.pages
|
||||
|
||||
@@ -15,6 +15,7 @@ use bds_core::model::{
|
||||
CategorySettings, Post, PostStatus, PostTranslation, Project, ProjectMetadata, Template,
|
||||
TemplateKind, TemplateStatus,
|
||||
};
|
||||
use bds_core::render::estimate_site_render_pages;
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn make_project() -> Project {
|
||||
@@ -435,6 +436,7 @@ fn section_generation_reports_its_urls_and_defers_pagefind() {
|
||||
&posts,
|
||||
GenerationSection::Single,
|
||||
|current, total, url| urls.push((current, total, url.to_string())),
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -469,6 +471,7 @@ fn section_generation_reports_its_urls_and_defers_pagefind() {
|
||||
&changed_posts,
|
||||
GenerationSection::Single,
|
||||
|_current, _total, _url| {},
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -477,6 +480,43 @@ fn section_generation_reports_its_urls_and_defers_pagefind() {
|
||||
assert!(!dir.path().join(old_fragment).exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_generation_reports_while_html_is_rendered_before_files_are_written() {
|
||||
let (db, dir) = setup();
|
||||
let metadata = make_metadata();
|
||||
let posts = vec![PublishedPostSource {
|
||||
post: make_post("hello", 1_710_000_000_000),
|
||||
body_markdown: "Hello **world**".into(),
|
||||
}];
|
||||
let output = dir.path().join("2024/03/09/hello/index.html");
|
||||
let rendered_before_write = std::sync::atomic::AtomicBool::new(false);
|
||||
let rendered = std::sync::atomic::AtomicUsize::new(0);
|
||||
let estimated = estimate_site_render_pages(dir.path(), &metadata, &[posts[0].post.clone()])
|
||||
.unwrap()[&GenerationSection::Single];
|
||||
|
||||
render_site_section_with_progress(
|
||||
db.conn(),
|
||||
dir.path(),
|
||||
"p1",
|
||||
&metadata,
|
||||
&posts,
|
||||
GenerationSection::Single,
|
||||
|_current, _total, _url| {},
|
||||
|_| {
|
||||
rendered.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
rendered_before_write.store(!output.exists(), std::sync::atomic::Ordering::Relaxed);
|
||||
},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(rendered_before_write.load(std::sync::atomic::Ordering::Relaxed));
|
||||
assert_eq!(
|
||||
rendered.load(std::sync::atomic::Ordering::Relaxed),
|
||||
estimated
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validation_apply_rewrites_only_the_reported_urls() {
|
||||
let (db, dir) = setup();
|
||||
@@ -508,6 +548,7 @@ fn validation_apply_rewrites_only_the_reported_urls() {
|
||||
&validation,
|
||||
GenerationSection::Single,
|
||||
|current, total, url| urls.push((current, total, url.to_string())),
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -599,6 +640,7 @@ fn page_aliases_belong_to_core_while_dated_posts_belong_to_single() {
|
||||
&posts,
|
||||
GenerationSection::Single,
|
||||
|_current, _total, _url| {},
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -613,6 +655,7 @@ fn page_aliases_belong_to_core_while_dated_posts_belong_to_single() {
|
||||
&posts,
|
||||
GenerationSection::Core,
|
||||
|_current, _total, _url| {},
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user