Skip to content

Commit

Permalink
filter returned cached polls
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirotw committed Apr 24, 2020
1 parent 6494736 commit d18dcff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils/makerdao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const formatYamlToJson = async data => {
}
}

export async function getPollsMetaData(polls) {
export async function getPollsMetaData(polls: Array<any>) {
const cached = (await getCache('polls-metadata')) || []
const cachedIds = cached.map(poll => poll.id)
const nonCached = cachedIds ? polls.filter(poll => !cachedIds.includes(poll.id)) : []
Expand Down Expand Up @@ -183,13 +183,14 @@ export async function getPollsMetaData(polls) {
...cachedData,
...newPollData,
}
}) // need to update data comming from subgraph
}) // need to update data coming from subgraph

const allPolls = [...updatedCached, ...pollsToAdd.filter(Boolean)]

await setCache('polls-metadata', allPolls)

return allPolls
const pollIds = polls.map(poll => poll.id)
return allPolls.filter(cachedPoll => pollIds.includes(cachedPoll.id))
}

export async function getMKRSupply() {
Expand Down

0 comments on commit d18dcff

Please sign in to comment.