Skip to content

Commit 23df2d1

Browse files
committed
refactoring the docker image get method to filetr using the map
1 parent 4f0cce7 commit 23df2d1

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/publishProject/projectUtils.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,36 @@ export async function getSqlServerContainerTagsForTargetVersion(
184184
return [];
185185
}
186186

187-
// Extract years from all available versions to find the maximum
188-
const availableYears = deploymentVersions
189-
.map((option) => parseInt(option.displayName.match(/\d{4}/)?.[0] || "0", 10))
190-
.filter((year) => year > 0);
187+
const yearToOptionMap = new Map<number, FormItemOptions>();
188+
for (const option of deploymentVersions) {
189+
const year = parseInt(option.value, 10);
190+
if (!isNaN(year)) {
191+
yearToOptionMap.set(year, option);
192+
}
193+
}
191194

192-
if (availableYears.length === 0) {
193-
return deploymentVersions; // No years found, return all
195+
if (yearToOptionMap.size === 0) {
196+
return deploymentVersions;
194197
}
195198

199+
const availableYears = Array.from(yearToOptionMap.keys());
196200
const maxYear = Math.max(...availableYears);
197201

198202
// Determine minimum year based on target version
199-
let minYear: number;
203+
let minYear: number = maxYear;
200204
if (targetVersion) {
201205
const versionNum = parseInt(targetVersion, 10);
202206
const mappedYear = DSP_VERSION_TO_YEAR.get(versionNum);
203-
// If we can map the version to a year, use it; otherwise fallback to max available year
204207
minYear = mappedYear ?? maxYear;
205-
} else {
206-
// No target version provided, fallback to max available year
207-
minYear = maxYear;
208208
}
209209

210-
// Filter deployment versions based on minimum year
211-
const filteredVersions = deploymentVersions.filter((option) => {
212-
const year = parseInt(option.displayName.match(/\d{4}/)?.[0] || "0", 10);
213-
return year >= minYear;
214-
});
210+
// Filter the image tags that are >= minYear
211+
const filteredVersions: FormItemOptions[] = [];
212+
for (const [year, option] of yearToOptionMap.entries()) {
213+
if (year >= minYear) {
214+
filteredVersions.push(option);
215+
}
216+
}
215217

216218
return filteredVersions;
217219
} catch (e) {

0 commit comments

Comments
 (0)