{
+ const cacheKey = `${network}-parsed-tally-${poll.pollId}`;
+ if (config.USE_FS_CACHE) {
+ const cachedTally = fsCacheGet(cacheKey, network);
+ if (cachedTally) {
+ return JSON.parse(cachedTally);
+ }
+ }
+
// if poll vote type is unknown, treat as ranked choice
const voteType: PollVoteType = poll.voteType || POLL_VOTE_TYPE.RANKED_VOTE;
// Builds raw poll tally
- const tally: RawPollTally = await backoffRetry(3, () =>
- fetchPollTally(poll.pollId, voteType, false, network)
- );
+ const tally: RawPollTally = await backoffRetry(3, () => fetchRawPollTally(poll.pollId, voteType, network));
const endUnix = new Date(poll.endDate).getTime() / 1000;
- const votesByAddress = await fetchVotesByAddresForPoll(poll.pollId, endUnix, network);
+ const votesByAddress = await fetchVotesByAddressForPoll(poll.pollId, endUnix, network);
const totalMkrParticipation = tally.totalMkrParticipation;
const winner: string = tally.winner || '';
const numVoters = tally.numVoters;
- const parsedTally = {
+ const tallyObject = {
pollVoteType: voteType,
options:
Object.keys(tally.options).length > 0
@@ -48,8 +57,13 @@ export async function getPollTally(poll: Poll, network: SupportedNetworks): Prom
votesByAddress
} as RawPollTally;
- if ('rounds' in tally) (parsedTally as RawPollTallyRankedChoice).rounds = tally.rounds;
+ if ('rounds' in tally) (tallyObject as RawPollTallyRankedChoice).rounds = tally.rounds;
+
+ const parsedTally = parseRawPollTally(tallyObject, poll);
+
+ if (config.USE_FS_CACHE && !isActivePoll(poll)) {
+ fsCacheSet(cacheKey, JSON.stringify(parsedTally), network);
+ }
- // Return parsed tally
- return parseRawPollTally(parsedTally, poll);
+ return parsedTally;
}
diff --git a/modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts b/modules/polling/helpers/parseRankedChoiceRawOptionId.ts
similarity index 81%
rename from modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts
rename to modules/polling/helpers/parseRankedChoiceRawOptionId.ts
index 67e659a4e..8418276a9 100644
--- a/modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts
+++ b/modules/polling/helpers/parseRankedChoiceRawOptionId.ts
@@ -1,6 +1,6 @@
import { paddedArray, toBuffer } from 'lib/utils';
-export function parseRawOptinIdRankedChoiceOption(rawValue?: string): number[] {
+export function parseRankedChoiceRawOptionId(rawValue?: string): number[] {
let rankedChoiceOption: number[] = [];
if (rawValue) {
const ballotBuffer = toBuffer(rawValue, { endian: 'little' });
diff --git a/package.json b/package.json
index e21918747..8df5d2122 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "governance-portal-v2",
"license": "AGPL-3.0-only",
- "version": "0.4.0",
+ "version": "0.4.1",
"jest": {
"testTimeout": 7000
},
diff --git a/pages/api/address/[address]/last-vote.ts b/pages/api/address/[address]/last-vote.ts
deleted file mode 100644
index ce75dd865..000000000
--- a/pages/api/address/[address]/last-vote.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import invariant from 'tiny-invariant';
-import { NextApiRequest, NextApiResponse } from 'next';
-import { isSupportedNetwork } from 'modules/web3/helpers/networks';
-import { fetchAddressPollVoteHistory } from 'modules/polling/api/fetchAddressPollVoteHistory';
-import { PollVoteHistory } from 'modules/polling/types/pollVoteHistory';
-import withApiHandler from 'modules/app/api/withApiHandler';
-import { DEFAULT_NETWORK } from 'modules/web3/constants/networks';
-import { resolveENS } from 'modules/web3/helpers/ens';
-import { getContracts } from 'modules/web3/helpers/getContracts';
-import { networkNameToChainId } from 'modules/web3/helpers/chain';
-import { getVoteProxyAddresses } from 'modules/app/helpers/getVoteProxyAddresses';
-
-/*
- Returns the last vote for a given address
-*/
-export default withApiHandler(
- async (
- req: NextApiRequest,
- res: NextApiResponse<{
- lastVote: PollVoteHistory;
- }>
- ) => {
- const network = (req.query.network as string) || DEFAULT_NETWORK.network;
- const tempAddress = req.query.address as string;
- invariant(isSupportedNetwork(network), `unsupported network ${network}`);
-
- const address = tempAddress.indexOf('.eth') !== -1 ? await resolveENS(tempAddress) : tempAddress;
-
- const contracts = getContracts(networkNameToChainId(network));
-
- const voteProxyAddress = await getVoteProxyAddresses(
- contracts.voteProxyFactory,
- address as string,
- network
- );
-
- const pollVoteHistory = await fetchAddressPollVoteHistory(
- voteProxyAddress.hotAddress ? voteProxyAddress.hotAddress : (address as string),
- network
- );
- const lastVote = pollVoteHistory.sort((a, b) => (a.blockTimestamp > b.blockTimestamp ? -1 : 1))[0];
-
- res.setHeader('Cache-Control', 's-maxage=15, stale-while-revalidate');
- res.status(200).json({
- lastVote
- });
- }
-);
diff --git a/pages/executive/[proposal-id].tsx b/pages/executive/[proposal-id].tsx
index b292de2c1..a1f1b7492 100644
--- a/pages/executive/[proposal-id].tsx
+++ b/pages/executive/[proposal-id].tsx
@@ -242,7 +242,7 @@ const ProposalView = ({ proposal, spellDiffs }: Props): JSX.Element => {
,
{comments ? (
-
+
) : (
{commentsError ? (