-
-
Notifications
You must be signed in to change notification settings - Fork 23.1k
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
fix: prevent totalCommitsFetch error result from being cached #2177
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportBase: 96.79% // Head: 97.23% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #2177 +/- ##
==========================================
+ Coverage 96.79% 97.23% +0.43%
==========================================
Files 22 22
Lines 3835 3902 +67
Branches 328 368 +40
==========================================
+ Hits 3712 3794 +82
+ Misses 121 106 -15
Partials 2 2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
This commit makes sure that when the `https://api.github.com/search/commits?q=author:anuraghazra` API fails the result is not cached.
ed60739
to
3123e68
Compare
@anuraghazra, maybe we can merge this this will stop people making issues about incorrect total commit count (See #2026 (comment)). |
}`, | ||
); | ||
} else { | ||
res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache unsuccessful responses. |
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 idea, but I'm just worried that this will make it so that vercel will need to execute more fresh invocations causing increased load when PATs get exhausted.
For example say we get 10k fresh requests per day, and we cache 70% of the requests, if PATs get exhausted we will render & cache the error card and after 4hour everything will go back to normal.
But if we do this, all those 10k requests need to be executed by vercel even though they will all respond with error card.
I think ideal solution would be to decrease the cache seconds on errors: instead of no-cache let's do 1h for error responses (1h since cache will invalidate the same time as PATs get revalidate)
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.
That is 100% true I overlooked that fact. Let's close this for now.
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.
@anuraghazra In that case, we should also change the following code back so that it caches the error:
github-readme-stats/api/wakatime.js
Line 84 in 0ff426d
return res.send(renderError(err.message, err.secondaryMessage)); |
github-readme-stats/api/top-langs.js
Line 81 in 0ff426d
res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. |
github-readme-stats/api/pin.js
Line 83 in 0ff426d
res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. |
github-readme-stats/api/index.js
Line 96 in 0ff426d
res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses. |
These were merged some time ago and might also be depleting the PATs. However, I suspect this catch block is only triggered when something goes wrong in our code.
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.
The fetcher handles errors using throw
as well as trycatch
, so that means that errors with the API as well as with our code should trigger the trycatch
in ./api/index.js
, right?
Trying it out in the browser with a random (nonexistent) username gives a no-cache header, so you're right; this should be changed back, since it has the same effect as whatever the PRs trying to do.
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.
@Zo-Bro-23 I changed the code. Please review #2448. 👍
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.
Can we close this PR now since #2448 does the same thing?
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.
This pull request handles errors from the REST API, which will write 0 commits to the card when it fails. While the other pull request handles other errors. I will update this one when #2448 is merged.
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.
As far as I understand, API errors will trigger Javascript errors, which means that what the other PR does will apply to API errors too.
github-readme-stats/src/fetchers/stats-fetcher.js
Lines 215 to 218 in 4b17300
throw new CustomError( | |
"Something went while trying to retrieve the stats data using the GraphQL API.", | |
CustomError.GRAPHQL_ERROR, | |
); |
The fetcher is throwing a Javascript error, so GraphQL errors should trigger the trycatch
block too right? Or am I missing something?
@anuraghazra Closing this for now. See #2177 (comment), as it might also be important. |
Re-opening this since we can use this code on private Vercel instances. |
86aafe8
to
8bc69e7
Compare
Closing this as I think we should switch to throwing an error when the REST API fails and then use |
|
This PR ensures that when the
https://api.github.com/search/commits?q=author:anuraghazra
API fails, the result is not cached. This prevents people from creating an issue because their commits are 0 for the 4-hour cache period. After this PR is merged, the0
total commits should only show up when the error occurs.