increase ballots loading speed

This commit is contained in:
Max Alekseenko 2020-04-17 15:12:59 +03:00
parent 5bb4a3d5ed
commit e569caf9f6
1 changed files with 15 additions and 13 deletions

View File

@ -242,12 +242,13 @@ class ContractsStore {
console.log(e.message) console.log(e.message)
} }
const allKeysPromise = this.getCards(keysNextBallotId, 'votingToChangeKeys') const [keysCards, minTresholdCards, proxyCards, emissionFundsCards] = await Promise.all([
const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold') this.getCards(keysNextBallotId, 'votingToChangeKeys'),
const allProxyPromise = this.getCards(proxyNextBallotId, 'votingToChangeProxy') this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold'),
const allEmissionFundsPromise = this.getCards(emissionFundsNextBallotId, 'votingToManageEmissionFunds') this.getCards(proxyNextBallotId, 'votingToChangeProxy'),
this.getCards(emissionFundsNextBallotId, 'votingToManageEmissionFunds')
await Promise.all([allKeysPromise, allMinThresholdPromise, allProxyPromise, allEmissionFundsPromise]) ])
ballotsStore.ballotCards = [...keysCards, ...minTresholdCards, ...proxyCards, ...emissionFundsCards]
const allBallotsIDsLength = const allBallotsIDsLength =
keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId + emissionFundsNextBallotId keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId + emissionFundsNextBallotId
@ -350,7 +351,7 @@ class ContractsStore {
<BallotKeysCard <BallotKeysCard
id={id} id={id}
type={ballotStore.BallotType.keys} type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length} key={contractType + id}
pos={ballotsStore.ballotCards.length} pos={ballotsStore.ballotCards.length}
votingState={votingState} votingState={votingState}
/> />
@ -361,7 +362,7 @@ class ContractsStore {
<BallotMinThresholdCard <BallotMinThresholdCard
id={id} id={id}
type={ballotStore.BallotType.minThreshold} type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length} key={contractType + id}
pos={ballotsStore.ballotCards.length} pos={ballotsStore.ballotCards.length}
votingState={votingState} votingState={votingState}
/> />
@ -372,7 +373,7 @@ class ContractsStore {
<BallotProxyCard <BallotProxyCard
id={id} id={id}
type={ballotStore.BallotType.proxy} type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length} key={contractType + id}
pos={ballotsStore.ballotCards.length} pos={ballotsStore.ballotCards.length}
votingState={votingState} votingState={votingState}
/> />
@ -383,7 +384,7 @@ class ContractsStore {
<BallotEmissionFundsCard <BallotEmissionFundsCard
id={id} id={id}
type={ballotStore.BallotType.emissionFunds} type={ballotStore.BallotType.emissionFunds}
key={ballotsStore.ballotCards.length} key={contractType + id}
pos={ballotsStore.ballotCards.length} pos={ballotsStore.ballotCards.length}
votingState={votingState} votingState={votingState}
/> />
@ -397,9 +398,10 @@ class ContractsStore {
} }
getCards = async (nextBallotId, contractType) => { getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) { const promises = Array(nextBallotId)
ballotsStore.ballotCards.push(await this.getCard(id, contractType)) .fill(undefined)
} .map((item, index) => this.getCard(index, contractType))
return Promise.all(promises)
} }
@action('Get all keys next ballot ids') @action('Get all keys next ballot ids')