-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contribution Count Shows Different Numbers - fixed #443 #460
Conversation
app/src/utils/data/contributions.ts
Outdated
const json = await res.json(); | ||
|
||
if (json.data.grantDonations.length) { | ||
return await fetchUntilAll(SUBGRAPH_URL, before, skip + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes needed:
- merge json response with
before
before recursive call - increment indexdb number to bust cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's where to increment the version
dgrants/app/src/utils/constants.ts
Lines 43 to 44 in 01f6205
// we can bump this version number to bust the users cache | |
version: 1, |
I contribute to 6 grants on my own wallet and for other users everything was fine, but the contributor user only fetched 2 contributions. This PR is still an improvement and will fix the problem for most users, but for fixing #443 completely I need to find the root of this problem as well. Maybe we should create a new issue for it. |
app/src/utils/constants.ts
Outdated
@@ -41,7 +41,7 @@ export const DefaultForageConfig: LocalForageConfig = { | |||
// this store should be used for any on-chain/off-chain data but never user data (as we might clear it without notice) | |||
name: 'dGrants', | |||
// we can bump this version number to bust the users cache | |||
version: 1, | |||
version: 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 3 and not 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what should I put, thought maybe some other PR is going to use 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no other open PRs changing this, so we should use 2 🙂
version: 3, | |
version: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
app/src/utils/data/contributions.ts
Outdated
@@ -56,7 +56,7 @@ export async function getContributions( | |||
|
|||
const limit = 100; | |||
|
|||
const fetchUntilAll = async (SUBGRAPH_URL: string, before = [], skip = 0): Promise<any[]> => { | |||
const fetchUntilAll = async (SUBGRAPH_URL: string, before: any[] = [], skip = 0): Promise<any[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should have stronger typing than any
, but we can save that for the PR that handles #463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we use type ContributionSubgraph instead of any.
@Ajand code-wise this looks good, but I'm not sure what exactly you mean here? Which users is this working for and which is it only fetching 2 contributions for? |
Let's assume there are 3 users. user 1 will contribute to 10 grants. for user2 and user3, everything is fine, but for user1 we gonna get inconsistent results. |
agree with @mds1 comments, so once those are resolved (and approved), I'll approve |
There was two problems with #470:
This approach works fine for now but if we're going to scale ( for example if we have 50 contributions in each block ) it doesn't work. We need to create a queue while processing the events and saving all contributions at once after processing. Also, it would be nice to find the root of double processing for contributor users so could stop it. Since I'm using a random number there is still a slim chance for some contributors to have some issues. |
Whats left here @Ajand ? Is this read for final review? @mk1r thoughts? |
Hi @phutchins . |
@phutchins yes looks good to me, are all of @mds1 concerns resolved? @Ajand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job!
The root of the bug was the "first" parameter in the GraphQL query which has a default number of 100 and was not handled:
{ grantDonations(where: {lastUpdatedBlockNumber_gte: ${fromBlock}, lastUpdatedBlockNumber_lte: ${blockNumber}}) { grantId tokenIn donationAmount from hash rounds lastUpdatedBlockNumber } }
so whenever the length of the contributions would go more than 100, the system would act inconsistently. I created a recursive function that will continue to fetch contributions until there is no more left.
It only works if the cached data is properly set before "fromBlock" which is not unless there are less than 100 contributions So do the hard refresh and remove the cached data