From cfb362a7b1ea40fb2a5292298e3ebad90faa4fe5 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Mon, 25 Nov 2024 15:58:36 +0300 Subject: [PATCH] webapp: Handle maintainers with 5 fields in per_repo counts Sixth field (num_projects_vulnerable) was added later than the column, and wasn't yet filled for maintainers which have no counter updates since then. --- .../src/views/maintainer/maintainer.rs | 35 ++++++++----------- .../tests/fixtures/maintainer_data.sql | 3 +- repology-webapp/tests/maintainer.rs | 8 +++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/repology-webapp/src/views/maintainer/maintainer.rs b/repology-webapp/src/views/maintainer/maintainer.rs index e76aa01..1118f06 100644 --- a/repology-webapp/src/views/maintainer/maintainer.rs +++ b/repology-webapp/src/views/maintainer/maintainer.rs @@ -28,7 +28,7 @@ pub struct Maintainer { pub num_projects_problematic: i32, pub num_projects_vulnerable: i32, - pub counts_per_repo: sqlx::types::Json>, + pub counts_per_repo: sqlx::types::Json>>, pub num_projects_per_category: sqlx::types::Json>, @@ -190,29 +190,22 @@ pub async fn maintainer( .then_with(|| a.name.cmp(&b.name)) }) .collect(); + let maintainer_repositories: Vec<_> = std::mem::take(&mut maintainer.counts_per_repo.0) .into_iter() - .map( - |( - name, - ( - num_packages, - num_projects, - num_projects_newest, - num_projects_outdated, - num_projects_problematic, - num_projects_vulnerable, - ), - )| MaintainerRepository { + .map(|(name, fields)| { + // there may be 5 or 6 fields - vulnerable projects count was added at some + // point and there are still maintainers which do not have it filled + MaintainerRepository { name, - num_packages: num_packages as usize, - num_projects: num_projects as usize, - num_projects_newest: num_projects_newest as usize, - num_projects_outdated: num_projects_outdated as usize, - num_projects_problematic: num_projects_problematic as usize, - num_projects_vulnerable: num_projects_vulnerable as usize, - }, - ) + num_packages: fields[0] as usize, + num_projects: fields[1] as usize, + num_projects_newest: fields[2] as usize, + num_projects_outdated: fields[3] as usize, + num_projects_problematic: fields[4] as usize, + num_projects_vulnerable: *fields.get(5).unwrap_or(&0) as usize, + } + }) .sorted_by(|a, b| { a.num_projects_newest .cmp(&b.num_projects_newest) diff --git a/repology-webapp/tests/fixtures/maintainer_data.sql b/repology-webapp/tests/fixtures/maintainer_data.sql index 928f8d6..db9a31a 100644 --- a/repology-webapp/tests/fixtures/maintainer_data.sql +++ b/repology-webapp/tests/fixtures/maintainer_data.sql @@ -3,4 +3,5 @@ INSERT INTO maintainers(id, maintainer, orphaned_at) VALUES INSERT INTO maintainers(id, maintainer, num_packages, num_projects, counts_per_repo, num_projects_per_category) VALUES (2, 'active@example.com', 10, 10, '{"freebsd":[10,11,12,13,14,15]}'::jsonb, '{"games":10}'::jsonb), - (3, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb); + (3, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb), + (4, 'no-vuln-column@example.com', 10, 10, '{"freebsd":[10,11,12,13,14]}'::jsonb, '{"games":10}'::jsonb); diff --git a/repology-webapp/tests/maintainer.rs b/repology-webapp/tests/maintainer.rs index 614be6d..cb5853e 100644 --- a/repology-webapp/tests/maintainer.rs +++ b/repology-webapp/tests/maintainer.rs @@ -58,4 +58,12 @@ async fn test_maintainer(pool: PgPool) { // contact section contains_not "mailto:active@example.com", ); + check_response!( + pool, + "/maintainer/no-vuln-column@example.com", + status OK, + content_type "text/html", + html_ok "allow_empty_tags,warnings_fatal", + // enough to just be deserialized without errors + ); }