From e569caf9f61c6ca1d138a04ac86f7da352fac252 Mon Sep 17 00:00:00 2001 From: Max Alekseenko Date: Fri, 17 Apr 2020 15:12:59 +0300 Subject: [PATCH] increase ballots loading speed --- src/stores/ContractsStore.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/stores/ContractsStore.js b/src/stores/ContractsStore.js index 5d98682..abad6fc 100644 --- a/src/stores/ContractsStore.js +++ b/src/stores/ContractsStore.js @@ -242,12 +242,13 @@ class ContractsStore { console.log(e.message) } - const allKeysPromise = this.getCards(keysNextBallotId, 'votingToChangeKeys') - const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold') - const allProxyPromise = this.getCards(proxyNextBallotId, 'votingToChangeProxy') - const allEmissionFundsPromise = this.getCards(emissionFundsNextBallotId, 'votingToManageEmissionFunds') - - await Promise.all([allKeysPromise, allMinThresholdPromise, allProxyPromise, allEmissionFundsPromise]) + const [keysCards, minTresholdCards, proxyCards, emissionFundsCards] = await Promise.all([ + this.getCards(keysNextBallotId, 'votingToChangeKeys'), + this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold'), + this.getCards(proxyNextBallotId, 'votingToChangeProxy'), + this.getCards(emissionFundsNextBallotId, 'votingToManageEmissionFunds') + ]) + ballotsStore.ballotCards = [...keysCards, ...minTresholdCards, ...proxyCards, ...emissionFundsCards] const allBallotsIDsLength = keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId + emissionFundsNextBallotId @@ -350,7 +351,7 @@ class ContractsStore { @@ -361,7 +362,7 @@ class ContractsStore { @@ -372,7 +373,7 @@ class ContractsStore { @@ -383,7 +384,7 @@ class ContractsStore { @@ -397,9 +398,10 @@ class ContractsStore { } getCards = async (nextBallotId, contractType) => { - for (let id = nextBallotId - 1; id >= 0; id--) { - ballotsStore.ballotCards.push(await this.getCard(id, contractType)) - } + const promises = Array(nextBallotId) + .fill(undefined) + .map((item, index) => this.getCard(index, contractType)) + return Promise.all(promises) } @action('Get all keys next ballot ids')