From 927f999e73518c8d729f853bc35e017a85926d82 Mon Sep 17 00:00:00 2001 From: Matthew John Date: Fri, 7 Jun 2024 06:31:25 +0100 Subject: [PATCH] Use map of pre-existing versions to improve lookup of recent versions in UI before appending all versions --- lib/install.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/install.go b/lib/install.go index baebb2ff..884bfc05 100644 --- a/lib/install.go +++ b/lib/install.go @@ -291,6 +291,8 @@ type VersionSelector struct { func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPath, installPath string, mirrorURL string) { var selectVersions []VersionSelector + var versionMap map[string]bool = make(map[string]bool) + // Add recent versions recentVersions, _ := getRecentVersions(installPath, product) for _, version := range recentVersions { @@ -298,19 +300,13 @@ func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPat Version: version, Label: version + " *recent", }) + versionMap[version] = true } // Add all versions tfList, _ := getTFList(mirrorURL, listAll) for _, version := range tfList { - isRecentVersion := false - for _, recentVersion := range recentVersions { - if recentVersion == version { - isRecentVersion = true - break - } - } - if !isRecentVersion { + if !versionMap[version] { selectVersions = append(selectVersions, VersionSelector{ Version: version, Label: version,