fix: hopefully fixed the background task progress situation

This commit is contained in:
2026-07-23 22:48:53 +02:00
parent ea90167a5a
commit 87318c8b22
16 changed files with 225 additions and 42 deletions

View File

@@ -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()))?;

View File

@@ -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,

View File

@@ -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(&section).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