Skip to content

Commit 7fa86a8

Browse files
committed
Only index the most current patch of each minor
1 parent dd8bc19 commit 7fa86a8

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/api.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('dotenv').config()
22

33
import { readJsonSync } from 'fs-extra'
44
import { difference } from 'lodash-es'
5-
import { compare as compareSemVers } from 'semver'
5+
import { gt, compare as compareSemVers } from 'semver'
66
import downloadApiDocs from './api-docs-sync'
77
import algoliaDriver from './drivers/algolia'
88
import jsonDriver from './drivers/json'
@@ -43,8 +43,12 @@ async function processDocs(driver, project) {
4343

4444
try {
4545
console.log(`Processing ${project} for versions: ${versionsToProcess}`)
46-
47-
await versionsToProcess
46+
// iterate versions and drop latest minor of each major in buckets
47+
let latestPatchesObj = versionsToProcess.sort(compareSemVers).reduce(addIfLatestPatch, {});
48+
// make an array of the latest minors you get
49+
let latestPatches = Object.values(latestPatchesObj);
50+
console.log('latest patches', latestPatches);
51+
await latestPatches
4852
.filter(version => filterMissingRevs(version, project))
4953
.map(version => readIndexFileForVersion(version, project))
5054
// Fetch all public modules and public classes
@@ -54,7 +58,6 @@ async function processDocs(driver, project) {
5458
// Run the schema against all data stored
5559
.map(mapDataForVersion)
5660
.map(content => writeToDriver(driver, content))
57-
5861
let versions = [...prevIndexedVersions, ...versionsToProcess].sort(
5962
compareSemVers
6063
)
@@ -69,6 +72,19 @@ async function processDocs(driver, project) {
6972
}
7073
}
7174

75+
function addIfLatestPatch(latestPatches, version) {
76+
let semvers = version.split('.')
77+
let major = semvers[0];
78+
let minor = semvers[1];
79+
let minorVersion = `${major}.${minor}`;
80+
if (minorVersion in latestPatches && gt(version, latestPatches[minorVersion])) {
81+
latestPatches[minorVersion] = version;
82+
} else if (!(minorVersion in latestPatches)) {
83+
latestPatches[minorVersion] = version;
84+
}
85+
return latestPatches;
86+
}
87+
7288
function filterMissingRevs(version, libName) {
7389
const emberVersionJSONPath = `./tmp/rev-index/${libName}-${version}.json`
7490
let isIncluded = true

0 commit comments

Comments
 (0)