Skip to content
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

Getting Github star / fork count is somewhat expensive #843

Closed
jrudolph opened this issue Aug 7, 2018 · 5 comments
Closed

Getting Github star / fork count is somewhat expensive #843

jrudolph opened this issue Aug 7, 2018 · 5 comments

Comments

@jrudolph
Copy link

jrudolph commented Aug 7, 2018

Description

Great work on the design!

Each time a page is opened, the star / fork count is loaded another time. Also it seems it tries to find the repository by enumerating all repositories of the user which might even need several round-trips to github to get this simple info.

No Javascript developer here, so please bear with me ;)

I'd suggest to:

  • cache Github results locally for some time
  • Fetch repository info directly (there's a comment somewhere that the enumeration is done to prevent 404, but why would 404s be a problem?)
@squidfunk
Copy link
Owner

Actually, GitHub stars are cached in a Cookie (could use Local Storage, yeah, but it works for now). The theme loads all projects from a user/organization because some people like to link their organization. This was implemented in #337.

@jrudolph
Copy link
Author

jrudolph commented Aug 7, 2018

Ah, I guess then the problem was that I tested on localhost.

I think with caching usually working, no reason to optimize further.

Sorry for the hiccup.

@jrudolph jrudolph closed this as completed Aug 7, 2018
@squidfunk
Copy link
Owner

Skimming through the code, I remember why we did it: some users use Material to host documentation for their private repositories. They enter the URL to their repository in mkdocs.yml in the repo_url attribute which Material reads and uses for querying the GitHub API. Private repos are not exposed, so the result when querying GitHub is a 404 error. Actually it's not possible to get private information from the GitHub API without authenticating (thankfully), so to omit the 404 error in the console we just query for all repos and see if we can find it. If not, Material will just show the name of the repo without any counts. This also introduced a new feature - just linking the organization will show how many repositories this organization has.

Why would somebody want to use this feature with a private repo? Because the repo_url in conjunction with edit_uri enables the inclusion of EDIT links on every page directly linking to the private repository.

The issue in which this was reported and discussed is #329.

@jrudolph
Copy link
Author

jrudolph commented Aug 8, 2018

Thanks for the information! 👍

@yashu1wwww
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants