#223 Fixed the rendering problem by replacing forEach loop
Merged 3 years ago by dustymabe. Opened 3 years ago by gursewak.
Unknown source multipleCallsFix  into  master

@@ -267,33 +267,36 @@

    let config = { builds, base, legacy };

    return gatherMetadataBtwReleases(fromIdx, toIdx, config).then(metaList => {

      let build = builds[fromIdx];

-     metaList.forEach(metaListData => {

-       var meta = {}

-       var finalCommitMeta = {}

-       metaListData.forEach(metaForEachArch => {

-         let basearch= metaForEachArch[0];

-         // Adding meta for each architecture

-         meta[basearch] = metaForEachArch[1]

-         // check if `parent-pkgdiff` field is present, if present there's no need to manually

-         // calculate pkgdiff here, use the field directly

-         // xref: https://github.com/coreos/fedora-coreos-pipeline/pull/247#event-3413080221

-         metaListForPkgDiff = []

-         metaListForPkgDiff.push(metaForEachArch)

-         meta[basearch].pkgdiff = meta[basearch]['parent-pkgdiff'] == null ? getPkgDiffFromMetaList(metaListForPkgDiff) : meta[basearch]['parent-pkgdiff'];

-         sortPkgDiff(meta[basearch]);

-         build.selectedArch = "x86_64"

-         build.meta = meta;

-         // and fetch extra commit metadata in async

-         return fetchBuildCommitMeta(base, build, basearch, legacy).then(commitmeta => {

-           // Adding commitmeta for each architecture

-           finalCommitMeta[basearch] = commitmeta

-           finalCommitMeta[basearch]["importantPkgs"] = findImportantPkgs(commitmeta);

-           finalCommitMeta[basearch]["showImportantPkgsOnly"] = true;

-           build.commitmeta = finalCommitMeta;

-           builds[fromIdx] = build;

-         });

-       });

-     });

+     var meta = {}

+     var finalCommitMeta = {}

+     let promises = []

+     // Fetch meta and commitmeta for each architecture for the build

+     for (const metaForEachArch of metaList[0]){

+       let basearch= metaForEachArch[0];

+       // Adding meta for each architecture

+       meta[basearch] = metaForEachArch[1]

+       // check if `parent-pkgdiff` field is present, if present there's no need to manually

+       // calculate pkgdiff here, use the field directly

+       // xref: https://github.com/coreos/fedora-coreos-pipeline/pull/247#event-3413080221

+       metaListForPkgDiff = []

+       metaListForPkgDiff.push(metaForEachArch)

+       meta[basearch].pkgdiff = meta[basearch]['parent-pkgdiff'] == null ? getPkgDiffFromMetaList(metaListForPkgDiff) : meta[basearch]['parent-pkgdiff'];

+       sortPkgDiff(meta[basearch]);

+       // Setting the default selectedArch for dropdown to x86_64

+       build.selectedArch = "x86_64"

+       build.meta = meta;

+       // and fetch extra commit metadata in async

+       promises.push(fetchBuildCommitMeta(base, build, basearch, legacy).then(commitmeta => {

+         // Adding commitmeta for each architecture

+         finalCommitMeta[basearch] = commitmeta

+         finalCommitMeta[basearch]["importantPkgs"] = findImportantPkgs(commitmeta);

+         finalCommitMeta[basearch]["showImportantPkgsOnly"] = true;

+         build.commitmeta = finalCommitMeta;

+         builds[fromIdx] = build;

+       }));

+     }

+     // Return a single promise when all the promises get resolved

+     return Promise.all(promises)  

    });

  }

  

forEach is not promise-aware so it was creating a problem with rendering all the streams. We could only view four streams when we had hard coded to view five of them. Switched it with the classic for loop and added the promises array instead of returning within the loop (since for loop stops when we return something).

LGTM - my only suggestion would be to add more comments in the code about the subtlety here.

rebased onto 63212aaed175c1176c035f5ff547921567bebf24

3 years ago

rebased onto 2f4719d

3 years ago

Pull-Request has been merged by dustymabe

3 years ago
Metadata