Skip to content

Commit

Permalink
fix: optimize proposals data requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Jan 10, 2024
1 parent 89220dd commit 2da4578
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ipfs_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 21 additions & 4 deletions src/proposals/store/proposalsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

1 comment on commit 2da4578

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.