From d6c739b1c576ec8f7b91473cc0a2dae125e4dbc4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 Sep 2021 18:42:28 +0200 Subject: [PATCH] Governance Bug Fxed. Calculations taking too long because of circular references with too many generations. Reduced to 3. --- .../Function-Libraries/DelegationProgram.js | 2 +- .../Function-Libraries/DistributionProcess.js | 20 ++++++++++++++++++- .../UI/Function-Libraries/VotingProgram.js | 2 +- .../Spaces/User-Profile-Space/UserProfile.js | 16 +++++++-------- .../UI/Utilities/DecendentProgram.js | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Projects/Governance/UI/Function-Libraries/DelegationProgram.js b/Projects/Governance/UI/Function-Libraries/DelegationProgram.js index b429ed4a0..f75f27668 100644 --- a/Projects/Governance/UI/Function-Libraries/DelegationProgram.js +++ b/Projects/Governance/UI/Function-Libraries/DelegationProgram.js @@ -2,7 +2,7 @@ function newGovernanceFunctionLibraryDelegationProgram() { let thisObject = { calculate: calculate } - const MAX_GENERATIONS = 10 + const MAX_GENERATIONS = 3 return thisObject diff --git a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js index 83cd58168..d880e271d 100644 --- a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js +++ b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js @@ -1,10 +1,24 @@ function newGovernanceFunctionLibraryDistributionProcess() { let thisObject = { - calculate: calculate + calculate: calculate, + finalize: finalize, + initialize: initialize } + const DISTRIBUTION_PROCESS_RECALCULATION_DELAY = 5000 + let loop + return thisObject + function initialize() { + loop = true + calculate() + } + + function finalize() { + loop = false + } + function calculate() { let pools = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Pools') @@ -125,5 +139,9 @@ function newGovernanceFunctionLibraryDistributionProcess() { UI.projects.governance.functionLibraries.tokenMining.calculate( userProfiles ) + + if (loop === true) { + setTimeout(calculate, DISTRIBUTION_PROCESS_RECALCULATION_DELAY) + } } } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/VotingProgram.js b/Projects/Governance/UI/Function-Libraries/VotingProgram.js index 7b1b6aca3..596ae1971 100644 --- a/Projects/Governance/UI/Function-Libraries/VotingProgram.js +++ b/Projects/Governance/UI/Function-Libraries/VotingProgram.js @@ -3,7 +3,7 @@ function newGovernanceFunctionLibraryVotingProgram() { calculate: calculate, installMissingVotes: installMissingVotes } - const MAX_GENERATIONS = 10 + const MAX_GENERATIONS = 3 return thisObject diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index d38898d0e..296f32f61 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -16,8 +16,6 @@ function newGovernanceUserProfileSpace() { let waitingForResponses = 0 const BSC_SCAN_RATE_LIMIT_DELAY = 6000 - const DISTRIBUTION_PROCESS_RECALCULATION_DELAY = 5000 - let intervalId let reputationByAddress = new Map() return thisObject @@ -31,8 +29,7 @@ function newGovernanceUserProfileSpace() { /* Here we will run the distribution process, that in turn will run all the programs. */ - intervalId = setInterval(UI.projects.governance.functionLibraries.distributionProcess.calculate, DISTRIBUTION_PROCESS_RECALCULATION_DELAY) - + UI.projects.governance.functionLibraries.distributionProcess.initialize() /* Here we will get a list of all github usernames who have a star or fork and are watching the Superalgos Repository. This will later be used to know which user profiles are participating @@ -301,15 +298,17 @@ function newGovernanceUserProfileSpace() { } function finalize() { - clearInterval(intervalId) - intervalId = undefined + + UI.projects.governance.functionLibraries.distributionProcess.finalize() thisObject.githubStars = undefined thisObject.githubWatchers = undefined thisObject.githubForks = undefined - thisObject.container.finalize() - thisObject.container = undefined + if (thisObject.container !== undefined) { + thisObject.container.finalize() + thisObject.container = undefined + } } function reset() { @@ -330,6 +329,7 @@ function newGovernanceUserProfileSpace() { } function physics() { + if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return } /* If the workspace is not related to governance, then we exit the Intialize Function diff --git a/Projects/Governance/UI/Utilities/DecendentProgram.js b/Projects/Governance/UI/Utilities/DecendentProgram.js index 3f604e612..446c5069f 100644 --- a/Projects/Governance/UI/Utilities/DecendentProgram.js +++ b/Projects/Governance/UI/Utilities/DecendentProgram.js @@ -7,7 +7,7 @@ function newGovernanceUtilitiesDecendentProgram() { let thisObject = { run: run } - const MAX_GENERATIONS = 10 + const MAX_GENERATIONS = 3 return thisObject