DenverCoder1 / github-readme-streak-stats

🔥 Stay motivated and show off your contribution streak! 🌟 Display your total contributions, current streak, and longest streak on your GitHub profile README
https://streak-stats.demolab.com
MIT License
4.92k stars 777 forks source link

Streak Card not fetching in Readme file #601

Open keshav-chandra opened 1 year ago

keshav-chandra commented 1 year ago

Describe the bug When I used GitHub's Streak URL in browser it was showing the streak card but when I had put it in ReadMe file it showed alternate text and link. May be due to the loading time of this API call as it always takes more than 20 seconds or sometimes failed to load and reflect application error.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'https://github.com/keshav-chandra'
  2. Click on 'Readme.md'
  3. Scroll down to 'GitHub Stats'
  4. See error

Expected behavior Using this https://streak-stats.demolab.com/?user=keshav-chandra&theme=calm link SVG or PNG, it should have shown the below result.

image

Screenshots

image

Desktop (please complete the following information):

DenverCoder1 commented 1 year ago

When there is a lot of traffic to the Heroku server, the GitHub API seems to stop sending back content and the responses become very slow. If it takes too long to load, GitHub will just show a broken image instead of waiting. GitHub also caches responses on their server, so even if the speed gets back to normal, it could still show as broken on GitHub for a particular image URL for up to a few hours.

To avoid this issue, I recommend self-hosting the project. There are steps in the readme, I recently added a new method for deploying with Vercel entirely online. It's free and shouldn't take more than a couple minutes to set up.

It should also start working on its own, but there isn't much I can do to prevent it from going down in the future, so self-hosting is still an option to get it to stay up more reliably.

XiovV commented 1 year ago

When there is a lot of traffic to the Heroku server, the GitHub API seems to stop sending back content and the responses become very slow. If it takes too long to load, GitHub will just show a broken image instead of waiting. GitHub also caches responses on their server, so even if the speed gets back to normal, it could still show as broken on GitHub for a particular image URL for up to a few hours.

To avoid this issue, I recommend self-hosting the project. There are steps in the readme, I recently added a new method for deploying with Vercel entirely online. It's free and shouldn't take more than a couple minutes to set up.

It should also start working on its own, but there isn't much I can do to prevent it from going down in the future, so self-hosting is still an option to get it to stay up more reliably.

@DenverCoder1 why not set up caching on the backend? Instead of calling the GitHub API on every request, you can cache a user's stats for a few hours and have it clear itself automatically, that way the number of calls do the GitHub API should reduce dramatically. Yes, the PNG won't pick up your new streak immediately until the cache invalidates, but this should be much better than GitHub showing a broken image. Considering how lightweight and simple this project is, I don't think you'd even have to use Redis or something similar for caching, just a regular hashmap and it should work fine (unless you're running multiple instances on the heroku server that is).

DenverCoder1 commented 1 year ago

Thanks for the suggestions, @XiovV.

I believe that GitHub is caching the images, but even with that, the server is overloaded with new requests. We have cache control headers set to tell servers to use cached versions for up to an hour. Maybe increasing this to be a few hours could help.

Only 1 instance is running on Heroku (using a Basic dyno formation). There is no persistent storage, but an external service could be used for caching if necessary, though.