Some tweaks

This commit is contained in:
Luke Street
2025-11-26 23:39:41 -07:00
parent 2eb746bf1f
commit 0f8bed27b3
4 changed files with 54 additions and 26 deletions
+6 -4
View File
@@ -52,7 +52,7 @@ impl Database {
let report_cache = Cache::<ReportKey, CachedReportFile>::builder() let report_cache = Cache::<ReportKey, CachedReportFile>::builder()
.max_capacity(8192) .max_capacity(8192)
.eviction_listener(|k, _v, _cause| { .eviction_listener(|k, _v, _cause| {
tracing::info!( tracing::debug!(
"Evicting report from cache: {}/{}@{}:{}", "Evicting report from cache: {}/{}@{}:{}",
k.owner, k.owner,
k.repo, k.repo,
@@ -63,9 +63,9 @@ impl Database {
.build(); .build();
let report_unit_cache = Cache::<UnitKey, Arc<ReportUnit>>::builder() let report_unit_cache = Cache::<UnitKey, Arc<ReportUnit>>::builder()
.weigher(|_, v| v.encoded_len() as u32) .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| { .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(); .build();
let db = Self { pool, report_cache, report_unit_cache }; let db = Self { pool, report_cache, report_unit_cache };
@@ -1177,7 +1177,9 @@ fn compress(data: &[u8]) -> Vec<u8> { COMPRESSOR.with_borrow_mut(|z| z.compress(
fn decompress(data: &[u8]) -> Result<Cow<'_, [u8]>> { fn decompress(data: &[u8]) -> Result<Cow<'_, [u8]>> {
match zstd::zstd_safe::get_frame_content_size(data) { match zstd::zstd_safe::get_frame_content_size(data) {
Ok(Some(size)) => { 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")), Ok(None) => Err(anyhow!("Decompressed data size is unknown")),
Err(_) => Ok(Cow::Borrowed(data)), // Assume uncompressed Err(_) => Ok(Cow::Borrowed(data)), // Assume uncompressed
+44 -21
View File
@@ -104,12 +104,12 @@ fn build_category_selection<'a>(
current_category: Option<&'a ReportCategory>, current_category: Option<&'a ReportCategory>,
default_category: &str, default_category: &str,
) -> CategorySelection<'a> { ) -> CategorySelection<'a> {
let all_url = let all_url = canonical_url
canonical_url.query_param("category", if default_category == "all" { None } else { Some("all") }); .query_param("category", if default_category == "all" { None } else { Some("all") });
let all_category = let all_category =
ReportCategoryItem { id: "all", name: "All", path: all_url.path_and_query().to_string() }; ReportCategoryItem { id: "all", name: "All", path: all_url.path_and_query().to_string() };
let mut categories =
let mut categories = vec![ReportCategoryGroup { category: all_category, subcategories: Vec::new() }]; vec![ReportCategoryGroup { category: all_category, subcategories: Vec::new() }];
for c in report_categories { for c in report_categories {
if let Some((parent_id, _)) = c.id.split_once('.') { if let Some((parent_id, _)) = c.id.split_once('.') {
@@ -151,15 +151,10 @@ fn build_category_selection<'a>(
.split_once('.') .split_once('.')
.map(|(top, _)| (top, Some(current_category_id))) .map(|(top, _)| (top, Some(current_category_id)))
.unwrap_or((current_category_id, None)); .unwrap_or((current_category_id, None));
let current_top_index = categories let current_top_index =
.iter() categories.iter().position(|c| c.category.id == current_top_id).unwrap_or(0);
.position(|c| c.category.id == current_top_id)
.unwrap_or(0);
let current_sub_index = current_sub_id.and_then(|id| { let current_sub_index = current_sub_id.and_then(|id| {
categories[current_top_index] categories[current_top_index].subcategories.iter().position(|sc| sc.id == id)
.subcategories
.iter()
.position(|sc| sc.id == id)
}); });
CategorySelection { categories, current_top_index, current_sub_index } CategorySelection { categories, current_top_index, current_sub_index }
@@ -677,8 +672,15 @@ async fn render_report(
current_user: Option<CurrentUser>, current_user: Option<CurrentUser>,
mut ctx: TemplateContext, mut ctx: TemplateContext,
) -> Result<Response, AppError> { ) -> Result<Response, AppError> {
let Scope { report, project_info, measures, current_category: current_category_ref, current_unit, units, label } = let Scope {
scope; report,
project_info,
measures,
current_category: current_category_ref,
current_unit,
units,
label,
} = scope;
let current_category = *current_category_ref; let current_category = *current_category_ref;
let mut commit_message = report.commit.message.clone(); let mut commit_message = report.commit.message.clone();
@@ -770,11 +772,20 @@ async fn render_report(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let CategorySelection { categories, current_top_index, current_sub_index } = 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_top_category = &categories[current_top_index];
let current_category_item = current_sub_index let current_category_item = current_sub_index
.map(|i| &current_top_category.subcategories[i]) .map(|i| current_top_category.subcategories[i].clone())
.unwrap_or(&current_top_category.category); .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 prev_commit_path = project_info.prev_commit.as_deref().map(|commit| {
let url = request_url.with_path(&format!( let url = request_url.with_path(&format!(
@@ -1028,7 +1039,7 @@ async fn render_report(
summary { (current_category_item.name) } summary { (current_category_item.name) }
ul { ul {
li { li {
a href=(current_top_category.category.path) { (current_top_category.category.name) } a href=(current_top_category.category.path) { "All" }
} }
@for sub in &current_top_category.subcategories { @for sub in &current_top_category.subcategories {
li { li {
@@ -1082,8 +1093,15 @@ async fn render_history(
mut ctx: TemplateContext, mut ctx: TemplateContext,
result: Vec<ReportHistoryEntry>, result: Vec<ReportHistoryEntry>,
) -> Result<Response, AppError> { ) -> Result<Response, AppError> {
let Scope { report, project_info, measures, current_category: current_category_ref, current_unit, units: _, label } = let Scope {
scope; report,
project_info,
measures,
current_category: current_category_ref,
current_unit,
units: _,
label,
} = scope;
let current_category = *current_category_ref; let current_category = *current_category_ref;
let request_url = Url::parse(&uri.to_string()).context("Failed to parse URI")?; 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 default_category = project_info.project.default_category();
let CategorySelection { categories, current_top_index, current_sub_index } = 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_top_category = &categories[current_top_index];
let current_category_item = current_sub_index let current_category_item = current_sub_index
.map(|i| &current_top_category.subcategories[i]) .map(|i| &current_top_category.subcategories[i])
+1 -1
View File
@@ -598,4 +598,4 @@ label:has(> input[type="checkbox"]) {
.mt-spacing { .mt-spacing {
margin-top: var(--pico-spacing); margin-top: var(--pico-spacing);
} }
+3
View File
@@ -42,6 +42,9 @@ export default defineConfig({
plugins: [pluginSass(), pluginTypeCheck(), pluginReact()], plugins: [pluginSass(), pluginTypeCheck(), pluginReact()],
server: { server: {
port: 3001, port: 3001,
headers: {
'Cross-Origin-Resource-Policy': 'cross-origin',
},
}, },
dev: { dev: {
// Load assets directly from dev server // Load assets directly from dev server