make groups of dependencyCount to do async by group

This commit is contained in:
Jonathan Rainville 2018-06-20 11:15:47 -04:00 committed by Iuri Matias
parent fe63bd4515
commit 2dd48ede77
2 changed files with 35 additions and 0 deletions

View File

@ -286,6 +286,40 @@ class ContractsManager {
}
}
callback();
},
function setDependencyCount(callback) {
let className;
function getDependencyCount(contractName, cycleDetector) {
if (!self.contractDependencies[contractName] || !self.contractDependencies[contractName].length) {
self.contracts[contractName].dependencyCount = 0;
return 0;
}
if (self.contracts[contractName].dependencyCount) {
// Already have that count
return self.contracts[contractName].dependencyCount;
}
let total = self.contractDependencies[contractName].length;
self.contractDependencies[contractName].some(dependencyName => {
if (cycleDetector.indexOf(dependencyName) > -1) {
// We are in a cycle because of the dependency, set both to Infinity
self.contracts[dependencyName].dependencyCount = Infinity;
total = Infinity;
return true;
}
cycleDetector.push(dependencyName);
total += getDependencyCount(dependencyName, cycleDetector);
});
self.contracts[contractName].dependencyCount = total;
return total;
}
let cycleDetector;
for (className in self.contracts) {
cycleDetector = [];
getDependencyCount(className, cycleDetector);
}
callback();
}
], function (err) {
if (err) {

View File

@ -1,4 +1,5 @@
let async = require('async');
const _ = require('underscore');
const ContractDeployer = require('./contract_deployer.js');
const cloneDeep = require('clone-deep');