-
Notifications
You must be signed in to change notification settings - Fork 166
refactor: simplify auth flow to avoid Github API calls as much as possible #106
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
Conversation
…sible Attempts to handle use cases that don't require repository permission lookups first to avoid hitting the Github API. When we do need to look at repository permissions, still attempts to use a global cache of public/private flags for repos so if any user has pulled that repo's info, and it's a public repo we can resolve read related permissions without hitting the API. When we need to load the details for a repository, load the user's full listing of repositories en masse/batch. Whenever we load a repo store the public/private fag in global cache. Improve the test suite to handle many of the typical cases.
Thanks, I’ll take a look at this. In the process of moving but will look at it when I can. |
I think we are going to test this PR on large scale. Each user (not a Jenkins Admin) who authenticates to our Jenkins with this plugin consumes 2,500 GitHub API calls (❗). I suspect because of the sheer number of GitHub orgs & repos managed by our Jenkins. |
@ojacques let's try to build this PR and use it in our test env. |
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.
Great! Local testing went well I'll be merging this for next release.
This has been released in github-oauth 0.32 |
return accessToken; | ||
} | ||
|
||
/** | ||
* Gets the Github server used for this token | ||
* @return githubServer | ||
*/ | ||
public String getGithubServer() { | ||
String getGithubServer() { |
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.
breaks binary compabitility with plugins that already using this method
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.
PR breaks binary compatibility by hiding methods
Thanks for pointing out. I’ll update the method to restore the previous call for that method |
GithubMyself me; | ||
try { | ||
me = usersByTokenCache.getIfPresent(token); | ||
if (me == null) { | ||
GHMyself ghMyself = getGitHub().getMyself(); | ||
me = new GithubMyself(ghMyself); | ||
usersByTokenCache.put(token, me); | ||
// Also stick into usersByIdCache (to have latest copy) | ||
String username = ghMyself.getLogin(); | ||
usersByIdCache.put(username, new GithubUser(ghMyself)); |
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.
is it possible this code is throwing an exception that is causing https://issues.jenkins-ci.org/browse/JENKINS-56997
It seems like this method is returning UNKNOWN_TOKEN
. I'm running into this issue when scanning my organization for a pipeline configuration if that helps.
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.
Thanks for the note I’ll investigate this
Follow on to #102
I apologize as this is a biggie. The goal here is to try and improve performance for typical users (non-admins) when making heavy use of github org folders/repos.
Attempts to handle use cases that don't require repository permission lookups first to avoid hitting the Github API at all when we can.
When we do need to look at repository permissions, still attempts to use a global cache of public/private flags for repos so if any user has pulled that repo's info and it's a public repo we can resolve read related permissions without hitting the API to grab the user's repos or the specific repo.
When we need to load the details for a repository, load the user's full listing of repositories en masse/batch first, and if not in that listing then load that repo.
Whenever we load any repo, store the public/private flag in the global/all-users cache.