From 91f843f7cef3e6ef91b3d1d92d7f4db03e6d6f85 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Wed, 5 Mar 2025 13:02:17 +0100 Subject: [PATCH] Fix performance issue --- .../MaintainerInfo/MaintainerInfoIndex+Model.swift | 12 ++++++------ .../MaintainerInfo/MaintainerInfoIndex+View.swift | 7 ++++--- Tests/AppTests/MaintainerInfoIndexModelTests.swift | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+Model.swift b/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+Model.swift index cb7978de7..a6fa3bdb8 100644 --- a/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+Model.swift +++ b/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+Model.swift @@ -51,13 +51,13 @@ extension MaintainerInfoIndex { valueToCopy: badgeMarkdown(for: type)) } - func packageScoreCategories() -> Node { - .forEach(0.. Node { + return .forEach(0.. [PackageScore] { guard let scoreDetails else { return [] } return Score.Category.allCases .sorted { $0.title < $1.title } diff --git a/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+View.swift b/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+View.swift index b2a9804af..969d595c3 100644 --- a/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+View.swift +++ b/Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+View.swift @@ -70,7 +70,8 @@ enum MaintainerInfoIndex { } override func content() -> Node { - .div( + let scoreCategories = model.scoreCategories() + return .div( .h2("Information for \(model.packageName) Maintainers"), .p( .text("Are you the author, or a maintainer of "), @@ -188,7 +189,7 @@ enum MaintainerInfoIndex { "This package has a total score of \(model.score) points. The Swift Package Index uses package score in combination with the relevancy of a search query to influence the ordering of search results." ), .p( - "The score is currently evaluated based on \(model.scoreCategories.count) traits, and the breakdown of each trait is shown below." + "The score is currently evaluated based on \(scoreCategories.count) traits, and the breakdown of each trait is shown below." ), .div( .class("package-score"), @@ -196,7 +197,7 @@ enum MaintainerInfoIndex { ), .div( .class("package-score-breakdown"), - model.packageScoreCategories() + Model.packageScoreCategories(for: scoreCategories) ), .p( "The package score is a work in progress. We have an ", diff --git a/Tests/AppTests/MaintainerInfoIndexModelTests.swift b/Tests/AppTests/MaintainerInfoIndexModelTests.swift index 38d7afbf0..c240aea0a 100644 --- a/Tests/AppTests/MaintainerInfoIndexModelTests.swift +++ b/Tests/AppTests/MaintainerInfoIndexModelTests.swift @@ -52,12 +52,12 @@ struct MaintainerInfoIndexModelTests { do { model.scoreDetails?.numberOfDependencies = 0 - let categories = model.scoreCategories + let categories = model.scoreCategories() #expect(categories["Dependencies"]?.description == "Has no dependencies.") } do { model.scoreDetails?.numberOfDependencies = nil - let categories = model.scoreCategories + let categories = model.scoreCategories() #expect(categories["Dependencies"]?.description == "No dependency information available.") } }