Skip to content

Commit 090eb85

Browse files
committed
Refactor package index project data component parsing code
There was an inefficient approach to populating the project data for package index components, where the slices were iterated over redundantly for each of the components they contained. At first perhaps a reasonable tradeoff for the sake of consistency and readability, the redundancy has became more significant over time as new components are added. With the pending addition of yet another for pluggable monitor support, it seems best to refactor now.
1 parent 4fcbd06 commit 090eb85

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

Diff for: internal/project/projectdata/packageindex.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,15 @@ func InitializeForPackageIndex() {
5454

5555
for _, packageData := range PackageIndexPackages() {
5656
packageIndexPlatforms = append(packageIndexPlatforms, getPackageIndexData(packageData.Object, packageData.JSONPointer, "platforms", packageData.ID, ":{{index . 0}}@{{index . 1}}", []string{"architecture", "version"})...)
57+
packageIndexTools = append(packageIndexTools, getPackageIndexData(packageData.Object, packageData.JSONPointer, "tools", packageData.ID, ":{{index . 0}}@{{index . 1}}", []string{"name", "version"})...)
5758
}
5859

5960
for _, platformData := range PackageIndexPlatforms() {
6061
packageIndexBoards = append(packageIndexBoards, getPackageIndexData(platformData.Object, platformData.JSONPointer, "boards", platformData.ID, " >> {{index . 0}}", []string{"name"})...)
61-
}
62-
63-
for _, platformData := range PackageIndexPlatforms() {
6462
packageIndexToolsDependencies = append(packageIndexToolsDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "toolsDependencies", platformData.ID, " >> {{index . 0}}:{{index . 1}}@{{index . 2}}", []string{"packager", "name", "version"})...)
65-
}
66-
67-
for _, platformData := range PackageIndexPlatforms() {
6863
packageIndexDiscoveryDependencies = append(packageIndexDiscoveryDependencies, getPackageIndexData(platformData.Object, platformData.JSONPointer, "discoveryDependencies", platformData.ID, " >> {{index . 0}}:{{index . 1}}", []string{"packager", "name"})...)
6964
}
7065

71-
for _, packageData := range PackageIndexPackages() {
72-
packageIndexTools = append(packageIndexTools, getPackageIndexData(packageData.Object, packageData.JSONPointer, "tools", packageData.ID, ":{{index . 0}}@{{index . 1}}", []string{"name", "version"})...)
73-
}
74-
7566
for _, toolData := range PackageIndexTools() {
7667
packageIndexSystems = append(packageIndexSystems, getPackageIndexData(toolData.Object, toolData.JSONPointer, "systems", toolData.ID, " >> {{index . 0}}", []string{"host"})...)
7768
}

0 commit comments

Comments
 (0)