From 2da4578ffded494b9848a0a6b70a2adbb913a721 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 10 Jan 2024 08:09:21 +0200 Subject: [PATCH] fix: optimize proposals data requests --- .github/workflows/ipfs_deploy.yml | 3 --- package.json | 2 +- src/proposals/store/proposalsSlice.ts | 25 +++++++++++++++++++++---- yarn.lock | 8 ++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ipfs_deploy.yml b/.github/workflows/ipfs_deploy.yml index dce97d14..e33e51dd 100644 --- a/.github/workflows/ipfs_deploy.yml +++ b/.github/workflows/ipfs_deploy.yml @@ -29,9 +29,6 @@ jobs: node-version-file: '.nvmrc' cache: 'yarn' - - name: Checkout submodules - run: git submodule update --recursive --init - - name: Packages install shell: sh run: yarn --frozen-lockfile --prefer-offline diff --git a/package.json b/package.json index 5d06f25a..b0311d79 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@bgd-labs/aave-address-book": "^2.13.3", - "@bgd-labs/aave-governance-ui-helpers": "^1.0.15-3a0b4f08fbd9e1650f3a570b83b76f5a90872d88.0", + "@bgd-labs/aave-governance-ui-helpers": "^1.0.15", "@bgd-labs/frontend-web3-utils": "^1.0.4-19dbd66bffa6f9723784771409aaa219bbe57b98.0", "@emotion/cache": "^11.11.0", "@emotion/react": "^11.11.3", diff --git a/src/proposals/store/proposalsSlice.ts b/src/proposals/store/proposalsSlice.ts index 2cab326c..34e58d50 100644 --- a/src/proposals/store/proposalsSlice.ts +++ b/src/proposals/store/proposalsSlice.ts @@ -18,6 +18,7 @@ import { VotingConfig, } from '@bgd-labs/aave-governance-ui-helpers'; import { IWalletSlice, StoreSlice } from '@bgd-labs/frontend-web3-utils'; +import dayjs from 'dayjs'; import { Draft, produce } from 'immer'; import { Hex } from 'viem'; @@ -565,16 +566,32 @@ export const createProposalsSlice: StoreSlice< get().cachedProposalsIds.find((id) => proposalId === id), ).length; + const timeToUpdate = dayjs().unix() + 3 * 1000 * 50; // now + 3 minutes; + + const filteredIds = ids.filter((id) => { + return !get().detailedProposalsData[id] + ? true + : (get().detailedProposalsData[id]?.lastUpdatedTimestamp || 0) > + timeToUpdate; + }); + + const idsForUpdateVotingInfo = ids.filter((id) => { + return !get().detailedProposalsData[id] + ? false + : (get().detailedProposalsData[id]?.lastUpdatedTimestamp || 0) < + timeToUpdate; + }); + let proposalsData: BasicProposal[] = []; - if (!!ids.length && isProposalNotInCache) { + if (!!filteredIds.length && isProposalNotInCache) { const fr = Math.max.apply( null, - ids.map((id) => id), + filteredIds.map((id) => id), ); const to = Math.min.apply( null, - ids.map((id) => id), + filteredIds.map((id) => id), ); proposalsData = await get().govDataService.getDetailedProposalsData( @@ -606,7 +623,7 @@ export const createProposalsSlice: StoreSlice< PAGE_SIZE, get().setRpcError, ); - } else if (!isProposalNotInCache) { + } else if (!isProposalNotInCache || !!idsForUpdateVotingInfo.length) { const proposals = ids.map((id) => get().detailedProposalsData[id]); proposalsData = await get().govDataService.getOnlyVotingMachineData( get().configs, diff --git a/yarn.lock b/yarn.lock index 7d671ba3..6dca5433 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1281,10 +1281,10 @@ resolved "https://registry.yarnpkg.com/@bgd-labs/aave-address-book/-/aave-address-book-2.13.3.tgz#a115c2677aeadd0398caa096436395fe07f4cf48" integrity sha512-9WQekYTCjeAuqjRouLHvYdE9R86Hp4m5v9QJhr9zGpsl8OE/YxpmI6QEz6o0gHMB3D6DhqwAZ3nakCouz7Cb+w== -"@bgd-labs/aave-governance-ui-helpers@^1.0.15-3a0b4f08fbd9e1650f3a570b83b76f5a90872d88.0": - version "1.0.15-3a0b4f08fbd9e1650f3a570b83b76f5a90872d88.0" - resolved "https://registry.yarnpkg.com/@bgd-labs/aave-governance-ui-helpers/-/aave-governance-ui-helpers-1.0.15-3a0b4f08fbd9e1650f3a570b83b76f5a90872d88.0.tgz#a04882429b2e5d38b5dcb3af54bd6dc7202780c3" - integrity sha512-+P/aWVXVT5Q3QKsD5fv0lSD2XzDd+X0idKi+hdallEAakTbW599ui/x2WIYBdAzQuIRkfT7x93cgPBQhHOy+CA== +"@bgd-labs/aave-governance-ui-helpers@^1.0.15": + version "1.0.15" + resolved "https://registry.yarnpkg.com/@bgd-labs/aave-governance-ui-helpers/-/aave-governance-ui-helpers-1.0.15.tgz#84fa85d0c927fc5a82aa2874a1c39390ed2363ed" + integrity sha512-q+vRX2R73cgdlet0/gKvXEgrkPuNDg9DSYo6blBi88s9iW4Z3i8HbJUS2wJXqeuBfTu26Pbhb5kmYOVJOykhHQ== dependencies: bs58 "^5.0.0" dayjs "^1.11.10"