Skip to content

Commit

Permalink
Bug 1467504 - convert _uniq() usages to ES6 (#3634)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottvincent authored and Cameron Dawson committed Jun 13, 2018
1 parent 1facc75 commit d184bd2
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 49 deletions.
17 changes: 8 additions & 9 deletions ui/js/controllers/perf/alerts.js
Expand Up @@ -476,15 +476,14 @@ perf.controller('AlertsCtrl', [
});
}

summary.downstreamSummaryIds = _.uniq((
summary.alerts.map((alert) => {
if (alert.status === phAlertStatusMap.DOWNSTREAM.id &&
alert.summary_id !== summary.id) {
return alert.summary_id;
}
return [];
})).reduce((a, b) => [...a, ...b], []));

summary.downstreamSummaryIds = [...new Set((
summary.alerts.map((alert) => {
if (alert.status === phAlertStatusMap.DOWNSTREAM.id &&
alert.summary_id !== summary.id) {
return alert.summary_id;
}
return [];
})).reduce((a, b) => [...a, ...b], []))];
});

// update master list + visibility
Expand Down
56 changes: 28 additions & 28 deletions ui/js/controllers/perf/compare.js
Expand Up @@ -200,8 +200,8 @@ perf.controller('CompareResultsCtrl', [

cmap.links.push({
title: 'graph',
href: PhCompare.getGraphsLink(_.map(_.uniq(
[$scope.originalProject, $scope.newProject]), function (project) {
href: PhCompare.getGraphsLink(_.map([...new Set(
[$scope.originalProject, $scope.newProject])], function (project) {
return {
projectName: project.name,
signature: oldSig,
Expand Down Expand Up @@ -230,8 +230,8 @@ perf.controller('CompareResultsCtrl', [

cmap.links.push({
title: 'graph',
href: PhCompare.getGraphsLink(_.map(_.uniq(
[$scope.originalProject, $scope.newProject]), function (project) {
href: PhCompare.getGraphsLink(_.map([...new Set(
[$scope.originalProject, $scope.newProject])], function (project) {
return {
projectName: project.name,
signature: oldSig,
Expand Down Expand Up @@ -283,10 +283,10 @@ perf.controller('CompareResultsCtrl', [
subtests: 0,
framework: $scope.filterOptions.framework.id,
}).then((originalSeriesList) => {
$scope.platformList = _.uniq(
_.map(originalSeriesList, 'platform'));
$scope.testList = _.uniq(
_.map(originalSeriesList, 'name'));
$scope.platformList = [...new Set(
_.map(originalSeriesList, 'platform'))];
$scope.testList = [...new Set(
_.map(originalSeriesList, 'name'))];
return PhCompare.getResultsMap($scope.originalProject.name,
originalSeriesList,
{ push_id: resultSetIds });
Expand All @@ -308,10 +308,10 @@ perf.controller('CompareResultsCtrl', [
}).then((newSeriesList) => {
$scope.platformList = _.union(
$scope.platformList,
_.uniq(_.map(newSeriesList, 'platform')));
[...new Set(_.map(newSeriesList, 'platform'))]);
$scope.testList = _.union(
$scope.testList,
_.uniq(_.map(newSeriesList, 'name')));
[...new Set(_.map(newSeriesList, 'name'))]);
return PhCompare.getResultsMap($scope.newProject.name,
newSeriesList,
{ push_id: [$scope.newResultSet.id] });
Expand All @@ -327,8 +327,8 @@ perf.controller('CompareResultsCtrl', [
subtests: 0,
framework: $scope.filterOptions.framework.id
}).then((originalSeriesList) => {
$scope.platformList = _.uniq(_.map(originalSeriesList, 'platform'));
$scope.testList = _.uniq(_.map(originalSeriesList, 'name'));
$scope.platformList = [...new Set(_.map(originalSeriesList, 'platform'))];
$scope.testList = [...new Set(_.map(originalSeriesList, 'name'))];
const startDateMs = ($scope.newResultSet.push_timestamp -
$scope.selectedTimeRange.value) * 1000;
const endDateMs = $scope.newResultSet.push_timestamp * 1000;
Expand All @@ -345,11 +345,11 @@ perf.controller('CompareResultsCtrl', [
}).then((newSeriesList) => {
$scope.platformList = _.union(
$scope.platformList,
_.uniq(_.map(newSeriesList, 'platform'))
[...new Set(_.map(newSeriesList, 'platform'))]
);
$scope.testList = _.union(
$scope.testList,
_.uniq(_.map(newSeriesList, 'name'))
[...new Set(_.map(newSeriesList, 'name'))]
);
return PhCompare.getResultsMap($scope.newProject.name,
newSeriesList,
Expand Down Expand Up @@ -571,10 +571,10 @@ perf.controller('CompareSubtestResultsCtrl', [
if ($scope.originalRevision) {
cmap.links = [{
title: 'graph',
href: PhCompare.getGraphsLink(_.map(_.uniq([
href: PhCompare.getGraphsLink(_.map([...new Set([
$scope.originalProject,
$scope.newProject
]), function (project) {
])], function (project) {
return {
projectName: project.name,
signature: oldSig,
Expand All @@ -599,10 +599,10 @@ perf.controller('CompareSubtestResultsCtrl', [
} else {
cmap.links = [{
title: 'graph',
href: PhCompare.getGraphsLink(_.map(_.uniq([
href: PhCompare.getGraphsLink(_.map([...new Set([
$scope.originalProject,
$scope.newProject
]), function (project) {
])], function (project) {
return {
projectName: project.name,
signature: oldSig,
Expand Down Expand Up @@ -747,7 +747,7 @@ perf.controller('CompareSubtestResultsCtrl', [
framework: $scope.filterOptions.framework
}).then(function (originalSubtestList) {
$scope.pageList = _.map(originalSubtestList, 'name');
$scope.platformList = _.uniq(_.map(originalSubtestList, 'platform'));
$scope.platformList = [...new Set(_.map(originalSubtestList, 'platform'))];
return PhCompare.getResultsMap($scope.originalProject.name,
originalSubtestList,
{ push_id: resultSetIds });
Expand Down Expand Up @@ -779,12 +779,12 @@ perf.controller('CompareSubtestResultsCtrl', [
parent_signature: $scope.newSignature,
framework: $scope.filterOptions.framework
}).then(function (newSeriesList) {
$scope.platformList = _.uniq(_.union(
$scope.platformList = [...new Set(_.union(
$scope.platformList,
_.map(newSeriesList, 'platform')));
$scope.testList = _.uniq(_.union(
_.map(newSeriesList, 'platform')))];
$scope.testList = [...new Set(_.union(
$scope.testList,
_.map(newSeriesList, 'name')));
_.map(newSeriesList, 'name')))];

return PhCompare.getResultsMap($scope.newProject.name,
newSeriesList,
Expand Down Expand Up @@ -826,7 +826,7 @@ perf.controller('CompareSubtestResultsCtrl', [
framework: $scope.filterOptions.framework
}).then(function (originalSubtestList) {
$scope.pageList = _.map(originalSubtestList, 'name');
$scope.platformList = _.uniq(_.map(originalSubtestList, 'platform'));
$scope.platformList = [...new Set(_.map(originalSubtestList, 'platform'))];
const startDateMs = ($scope.newResultSet.push_timestamp -
$scope.selectedTimeRange.value) * 1000;
const endDateMs = $scope.newResultSet.push_timestamp * 1000;
Expand All @@ -846,12 +846,12 @@ perf.controller('CompareSubtestResultsCtrl', [
parent_signature: $scope.newSignature,
framework: $scope.filterOptions.framework
}).then(function (newSeriesList) {
$scope.platformList = _.uniq(_.union(
$scope.platformList = [...new Set(_.union(
$scope.platformList,
_.map(newSeriesList, 'platform')));
$scope.testList = _.uniq(_.union(
_.map(newSeriesList, 'platform')))];
$scope.testList = [...new Set(_.union(
$scope.testList,
_.map(newSeriesList, 'name')));
_.map(newSeriesList, 'name')))];

return PhCompare.getResultsMap($scope.newProject.name,
newSeriesList,
Expand Down
4 changes: 2 additions & 2 deletions ui/js/controllers/perf/dashboard.js
Expand Up @@ -86,10 +86,10 @@ perf.controller('dashCtrl', [
}

getSeriesList.then(function (seriesToMeasure) {
$scope.platformList = _.uniq(_.map(seriesToMeasure, 'platform'));
$scope.platformList = [...new Set(_.map(seriesToMeasure, 'platform'))];
// we just use the unadorned suite name to distinguish tests in this view
// (so we can mash together pgo and opt)
$scope.testList = _.uniq(_.map(seriesToMeasure, 'testName'));
$scope.testList = [...new Set(_.map(seriesToMeasure, 'testName'))];

$q.all(_.chunk(seriesToMeasure, 40).map(function (seriesChunk) {
const params = {
Expand Down
8 changes: 4 additions & 4 deletions ui/js/models/perf/alerts.js
Expand Up @@ -212,15 +212,15 @@ treeherder.factory('PhAlerts', [
title = "Empty alert";
}
// add test info
title += " " + _.uniq(
title += " " + [...new Set(
_.map(alertsInSummary, function (a) {
return PhSeries.getTestName(a.series_signature);
})).sort().join(' / ');
}))].sort().join(' / ');
// add platform info
title += " (" + _.uniq(
title += " (" + [...new Set(
_.map(alertsInSummary, function (a) {
return a.series_signature.machine_platform;
})).sort().join(', ') + ')';
}))].sort().join(', ') + ')';
return title;
};
AlertSummary.prototype.assignBug = function (taskNumber, issueTrackerId) {
Expand Down
4 changes: 2 additions & 2 deletions ui/js/models/perf/series.js
Expand Up @@ -9,15 +9,15 @@ treeherder.factory('PhSeries', ['$http', '$q', function ($http, $q) {
const _getTestName = function (signatureProps) {
// only return suite name if testname is identical, and handle
// undefined test name
return _.uniq([signatureProps.suite, signatureProps.test].filter(item => item)).join(" ");
return [...new Set([signatureProps.suite, signatureProps.test].filter(item => item))].join(" ");
};

const _getSeriesOptions = function (signatureProps, optionCollectionMap) {
let options = [optionCollectionMap[signatureProps.option_collection_hash]];
if (signatureProps.extra_options) {
options = options.concat(signatureProps.extra_options);
}
return _.uniq(options);
return [...new Set(options)];
};

const _getSeriesName = function (signatureProps, optionCollectionMap,
Expand Down
4 changes: 2 additions & 2 deletions ui/js/services/jobfilters.js
Expand Up @@ -280,7 +280,7 @@ treeherder.factory('thJobFilters', [
// set the value to an array
newQsVal = _toArray(oldQsVal);
newQsVal.push(value);
newQsVal = _.uniq(newQsVal);
newQsVal = [...new Set(newQsVal)];
} else {
newQsVal = value;
}
Expand Down Expand Up @@ -366,7 +366,7 @@ treeherder.factory('thJobFilters', [
if (_.difference(resultStatuses, rsValues).length === 0) {
rsValues = _.difference(rsValues, resultStatuses);
} else {
rsValues = _.uniq(rsValues.concat(resultStatuses));
rsValues = [...new Set(rsValues.concat(resultStatuses))];
}
// remove all query string params for this field if we match the defaults
if (_matchesDefaults(RESULT_STATUS, rsValues)) {
Expand Down
2 changes: 1 addition & 1 deletion ui/js/services/perf/compare.js
Expand Up @@ -236,7 +236,7 @@ treeherder.factory('PhCompare', [
seriesChunk => PhSeries.getSeriesData(
projectName, {
signature_id: _.map(seriesChunk, 'id'),
framework: _.uniq(_.map(seriesChunk, 'frameworkId')),
framework: [...new Set(_.map(seriesChunk, 'frameworkId'))],
...params
}).then((seriesData) => {
// Aggregates data from the server on a single group of values which
Expand Down
2 changes: 1 addition & 1 deletion ui/plugins/controller.js
Expand Up @@ -269,7 +269,7 @@ treeherder.controller('PluginCtrl', [

const performanceData = (Object.values(results[3])).reduce((a, b) => [...a, ...b], []);
if (performanceData) {
const signatureIds = _.uniq(_.map(performanceData, 'signature_id'));
const signatureIds = [...new Set(_.map(performanceData, 'signature_id'))];
$q.all(_.chunk(signatureIds, 20).map(
signatureIdChunk => PhSeries.getSeriesList($scope.repoName, { id: signatureIdChunk })
)).then((seriesListList) => {
Expand Down

0 comments on commit d184bd2

Please sign in to comment.