diff --git a/lib/modules/datasource/maven/index.ts b/lib/modules/datasource/maven/index.ts index 7e9f3e5faf74a8..b0b22d9336f680 100644 --- a/lib/modules/datasource/maven/index.ts +++ b/lib/modules/datasource/maven/index.ts @@ -3,6 +3,7 @@ import { DateTime } from 'luxon'; import type { XmlDocument } from 'xmldoc'; import { logger } from '../../../logger'; import * as packageCache from '../../../util/cache/package'; +import { filterMap } from '../../../util/filter-map'; import * as p from '../../../util/promises'; import { newlineRegex, regEx } from '../../../util/regex'; import { ensureTrailingSlash } from '../../../util/url'; @@ -220,11 +221,14 @@ export class MavenDatasource extends Datasource { // // Even if new version is being released each 10 minutes, // we still want to reset the whole cache after 24 hours. - const isCacheValid = await packageCache.get(cacheTimeoutNs, cacheKey); + const cacheValid = await packageCache.get<'valid'>( + cacheTimeoutNs, + cacheKey, + ); let cachedReleaseMap: ReleaseMap = {}; // istanbul ignore if - if (isCacheValid) { + if (cacheValid) { const cache = await packageCache.get(cacheNs, cacheKey); if (cache) { cachedReleaseMap = cache; @@ -232,8 +236,9 @@ export class MavenDatasource extends Datasource { } // List versions to check with HEAD request - const freshVersions = Object.entries(releaseMap) - .filter(([version, release]) => { + const freshVersions = filterMap( + Object.entries(releaseMap), + ([version, release]) => { // Release is present in maven-metadata.xml, // but haven't been validated yet const isValidatedAtPreviousSteps = release !== null; @@ -241,10 +246,15 @@ export class MavenDatasource extends Datasource { // Release was validated and cached with HEAD request during previous run const isValidatedHere = !is.undefined(cachedReleaseMap[version]); + // istanbul ignore if: not easily testable + if (isValidatedAtPreviousSteps || isValidatedHere) { + return null; + } + // Select only valid releases not yet verified with HEAD request - return !isValidatedAtPreviousSteps && !isValidatedHere; - }) - .map(([k]) => k); + return version; + }, + ); // Update cached data with freshly discovered versions if (freshVersions.length) { @@ -270,9 +280,9 @@ export class MavenDatasource extends Datasource { await p.all(queue); - if (!isCacheValid) { + if (!cacheValid) { // Store new TTL flag for 24 hours if the previous one is invalidated - await packageCache.set(cacheTimeoutNs, cacheKey, 'long', 24 * 60); + await packageCache.set(cacheTimeoutNs, cacheKey, 'valid', 24 * 60); } // Store updated cache object