From 38f32804f955749eb9464c30248cb4b036c05b1b Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 20 Jun 2018 11:15:47 -0400 Subject: [PATCH] make groups of dependencyCount to do async by group --- lib/modules/contracts_manager/index.js | 34 ++++++++++++++++++++++++++ lib/modules/deployment/index.js | 1 + 2 files changed, 35 insertions(+) diff --git a/lib/modules/contracts_manager/index.js b/lib/modules/contracts_manager/index.js index 137e5b70..38e85724 100644 --- a/lib/modules/contracts_manager/index.js +++ b/lib/modules/contracts_manager/index.js @@ -291,6 +291,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) { diff --git a/lib/modules/deployment/index.js b/lib/modules/deployment/index.js index 3dad132d..63c11ea1 100644 --- a/lib/modules/deployment/index.js +++ b/lib/modules/deployment/index.js @@ -1,4 +1,5 @@ let async = require('async'); +const _ = require('underscore'); const utils = require('../utils/utils.js'); //require("../utils/debug_util.js")(__filename, async);