Skip to content

Commit f379cd2

Browse files
Merge pull request #3713 from SwiftPackageIndex/fix-MaintainerInfoIndex-performance
Fix performance issue
2 parents e048289 + 91f843f commit f379cd2

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+Model.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ extension MaintainerInfoIndex {
5151
valueToCopy: badgeMarkdown(for: type))
5252
}
5353

54-
func packageScoreCategories() -> Node<HTML.BodyContext> {
55-
.forEach(0..<scoreCategories.count, { index in
54+
static func packageScoreCategories(for categories: [PackageScore]) -> Node<HTML.BodyContext> {
55+
return .forEach(0..<categories.count, { index in
5656
.div(
5757
.class("score-trait"),
58-
.p("\(scoreCategories[index].title)"),
59-
.p("\(scoreCategories[index].score) points"),
60-
.p("\(scoreCategories[index].description)")
58+
.p("\(categories[index].title)"),
59+
.p("\(categories[index].score) points"),
60+
.p("\(categories[index].description)")
6161
)
6262
})
6363
}
@@ -66,7 +66,7 @@ extension MaintainerInfoIndex {
6666
"https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/discussions/2591"
6767
}
6868

69-
var scoreCategories: [PackageScore] {
69+
func scoreCategories() -> [PackageScore] {
7070
guard let scoreDetails else { return [] }
7171
return Score.Category.allCases
7272
.sorted { $0.title < $1.title }

Sources/App/Views/PackageController/MaintainerInfo/MaintainerInfoIndex+View.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ enum MaintainerInfoIndex {
7070
}
7171

7272
override func content() -> Node<HTML.BodyContext> {
73-
.div(
73+
let scoreCategories = model.scoreCategories()
74+
return .div(
7475
.h2("Information for \(model.packageName) Maintainers"),
7576
.p(
7677
.text("Are you the author, or a maintainer of "),
@@ -188,15 +189,15 @@ enum MaintainerInfoIndex {
188189
"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."
189190
),
190191
.p(
191-
"The score is currently evaluated based on \(model.scoreCategories.count) traits, and the breakdown of each trait is shown below."
192+
"The score is currently evaluated based on \(scoreCategories.count) traits, and the breakdown of each trait is shown below."
192193
),
193194
.div(
194195
.class("package-score"),
195196
.text("Total – \(model.score) points")
196197
),
197198
.div(
198199
.class("package-score-breakdown"),
199-
model.packageScoreCategories()
200+
Model.packageScoreCategories(for: scoreCategories)
200201
),
201202
.p(
202203
"The package score is a work in progress. We have an ",

Tests/AppTests/MaintainerInfoIndexModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ struct MaintainerInfoIndexModelTests {
5252

5353
do {
5454
model.scoreDetails?.numberOfDependencies = 0
55-
let categories = model.scoreCategories
55+
let categories = model.scoreCategories()
5656
#expect(categories["Dependencies"]?.description == "Has no dependencies.")
5757
}
5858
do {
5959
model.scoreDetails?.numberOfDependencies = nil
60-
let categories = model.scoreCategories
60+
let categories = model.scoreCategories()
6161
#expect(categories["Dependencies"]?.description == "No dependency information available.")
6262
}
6363
}

0 commit comments

Comments
 (0)