From 0f8bed27b3becd272e1a1fd45f433e1355e4d9ef Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 26 Nov 2025 23:39:41 -0700 Subject: [PATCH] Some tweaks --- crates/db/src/lib.rs | 10 +++-- crates/web/src/handlers/report.rs | 65 +++++++++++++++++++++---------- css/main.scss | 2 +- rsbuild.config.ts | 3 ++ 4 files changed, 54 insertions(+), 26 deletions(-) diff --git a/crates/db/src/lib.rs b/crates/db/src/lib.rs index e391f8b..7463f15 100644 --- a/crates/db/src/lib.rs +++ b/crates/db/src/lib.rs @@ -52,7 +52,7 @@ impl Database { let report_cache = Cache::::builder() .max_capacity(8192) .eviction_listener(|k, _v, _cause| { - tracing::info!( + tracing::debug!( "Evicting report from cache: {}/{}@{}:{}", k.owner, k.repo, @@ -63,9 +63,9 @@ impl Database { .build(); let report_unit_cache = Cache::>::builder() .weigher(|_, v| v.encoded_len() as u32) - .max_capacity(256 * 1024 * 1024) // 256 MB + .max_capacity(512 * 1024 * 1024) // 512 MB .eviction_listener(|k, _v, _cause| { - tracing::info!("Evicting report unit from cache: {:?}", hex::encode(k.as_ref())); + tracing::debug!("Evicting report unit from cache: {:?}", hex::encode(k.as_ref())); }) .build(); let db = Self { pool, report_cache, report_unit_cache }; @@ -1177,7 +1177,9 @@ fn compress(data: &[u8]) -> Vec { COMPRESSOR.with_borrow_mut(|z| z.compress( fn decompress(data: &[u8]) -> Result> { match zstd::zstd_safe::get_frame_content_size(data) { Ok(Some(size)) => { - Ok(Cow::Owned(DECOMPRESSOR.with_borrow_mut(|z| z.decompress(data, size as usize))?)) + let mut buffer = Vec::with_capacity(size as usize); + DECOMPRESSOR.with_borrow_mut(|z| z.decompress_to_buffer(data, &mut buffer))?; + Ok(Cow::Owned(buffer)) } Ok(None) => Err(anyhow!("Decompressed data size is unknown")), Err(_) => Ok(Cow::Borrowed(data)), // Assume uncompressed diff --git a/crates/web/src/handlers/report.rs b/crates/web/src/handlers/report.rs index 364c776..c42d4c4 100644 --- a/crates/web/src/handlers/report.rs +++ b/crates/web/src/handlers/report.rs @@ -104,12 +104,12 @@ fn build_category_selection<'a>( current_category: Option<&'a ReportCategory>, default_category: &str, ) -> CategorySelection<'a> { - let all_url = - canonical_url.query_param("category", if default_category == "all" { None } else { Some("all") }); + let all_url = canonical_url + .query_param("category", if default_category == "all" { None } else { Some("all") }); let all_category = ReportCategoryItem { id: "all", name: "All", path: all_url.path_and_query().to_string() }; - - let mut categories = vec![ReportCategoryGroup { category: all_category, subcategories: Vec::new() }]; + let mut categories = + vec![ReportCategoryGroup { category: all_category, subcategories: Vec::new() }]; for c in report_categories { if let Some((parent_id, _)) = c.id.split_once('.') { @@ -151,15 +151,10 @@ fn build_category_selection<'a>( .split_once('.') .map(|(top, _)| (top, Some(current_category_id))) .unwrap_or((current_category_id, None)); - let current_top_index = categories - .iter() - .position(|c| c.category.id == current_top_id) - .unwrap_or(0); + let current_top_index = + categories.iter().position(|c| c.category.id == current_top_id).unwrap_or(0); let current_sub_index = current_sub_id.and_then(|id| { - categories[current_top_index] - .subcategories - .iter() - .position(|sc| sc.id == id) + categories[current_top_index].subcategories.iter().position(|sc| sc.id == id) }); CategorySelection { categories, current_top_index, current_sub_index } @@ -677,8 +672,15 @@ async fn render_report( current_user: Option, mut ctx: TemplateContext, ) -> Result { - let Scope { report, project_info, measures, current_category: current_category_ref, current_unit, units, label } = - scope; + let Scope { + report, + project_info, + measures, + current_category: current_category_ref, + current_unit, + units, + label, + } = scope; let current_category = *current_category_ref; let mut commit_message = report.commit.message.clone(); @@ -770,11 +772,20 @@ async fn render_report( .collect::>(); let CategorySelection { categories, current_top_index, current_sub_index } = - build_category_selection(&canonical_url, &report.report.categories, current_category, default_category); + build_category_selection( + &canonical_url, + &report.report.categories, + current_category, + default_category, + ); let current_top_category = &categories[current_top_index]; let current_category_item = current_sub_index - .map(|i| ¤t_top_category.subcategories[i]) - .unwrap_or(¤t_top_category.category); + .map(|i| current_top_category.subcategories[i].clone()) + .unwrap_or_else(|| ReportCategoryItem { + id: current_top_category.category.id, + name: "All", + path: current_top_category.category.path.clone(), + }); let prev_commit_path = project_info.prev_commit.as_deref().map(|commit| { let url = request_url.with_path(&format!( @@ -1028,7 +1039,7 @@ async fn render_report( summary { (current_category_item.name) } ul { li { - a href=(current_top_category.category.path) { (current_top_category.category.name) } + a href=(current_top_category.category.path) { "All" } } @for sub in ¤t_top_category.subcategories { li { @@ -1082,8 +1093,15 @@ async fn render_history( mut ctx: TemplateContext, result: Vec, ) -> Result { - let Scope { report, project_info, measures, current_category: current_category_ref, current_unit, units: _, label } = - scope; + let Scope { + report, + project_info, + measures, + current_category: current_category_ref, + current_unit, + units: _, + label, + } = scope; let current_category = *current_category_ref; let request_url = Url::parse(&uri.to_string()).context("Failed to parse URI")?; @@ -1111,7 +1129,12 @@ async fn render_history( let default_category = project_info.project.default_category(); let CategorySelection { categories, current_top_index, current_sub_index } = - build_category_selection(&canonical_url, &report.report.categories, current_category, default_category); + build_category_selection( + &canonical_url, + &report.report.categories, + current_category, + default_category, + ); let current_top_category = &categories[current_top_index]; let current_category_item = current_sub_index .map(|i| ¤t_top_category.subcategories[i]) diff --git a/css/main.scss b/css/main.scss index 07fc7ab..577ed04 100644 --- a/css/main.scss +++ b/css/main.scss @@ -598,4 +598,4 @@ label:has(> input[type="checkbox"]) { .mt-spacing { margin-top: var(--pico-spacing); -} \ No newline at end of file +} diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 38d0c7f..5ae3a86 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -42,6 +42,9 @@ export default defineConfig({ plugins: [pluginSass(), pluginTypeCheck(), pluginReact()], server: { port: 3001, + headers: { + 'Cross-Origin-Resource-Policy': 'cross-origin', + }, }, dev: { // Load assets directly from dev server