PyGithub icon indicating copy to clipboard operation
PyGithub copied to clipboard

Unnecessary API requests

Open jake-nz opened this issue 4 years ago • 3 comments

From my reading of the code, it seems that posting a Reaction to an Issue Comment results in two unnecessary get requests. I haven't been able to watch the actual network traffic to verify this though.

In the following example it looks like the two get requests will be mabe but are not needed.

# No API call because of lazy=True
repo = github.get_repo(repo_name, lazy=True)
# GET: /repos/{owner}/{repo}/issues/{id}
issue = repo.get_issue(number=issue_id)
# GET: /repos/{owner}/{repo}/issues/comments/{id}
comment = issue.get_comment(comment_id)
# POST: /repos/{owner}/{repo}/issues/comments/{id}/reactions
reaction = comment.create_reaction(reaction_type)

Is this right? Can we add lazy to all get methods?

jake-nz avatar Oct 28 '21 03:10 jake-nz

Can we add lazy to all get methods?

A possible alternative would be to provide easier ways to create child objects directly e.g. here the entire traversal is useless what you really want is to create an IssueComment directly from the bare minimum metadata because you're assuming / asserting the existence of the issue and comment id (because you got the information from somewhere else e.g. a webhook).

xmo-odoo avatar Nov 24 '21 12:11 xmo-odoo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 11:04 stale[bot]

I like @xmo-odoo's idea too!

If I can get feedback from the maintainers on this aproach and an indication that the project is still active. If I submit a PR for this, is it likely to get reviewed and accepted?

jake-nz avatar Apr 20 '22 00:04 jake-nz

I'd go for adding lazy to get_issue and get_comment. Because that way, many more methods on Issue and IssueComment can be used without firing API requests.

It's worth creating a PR.

EnricoMi avatar Jun 19 '23 08:06 EnricoMi