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

Add support for count operations whereever there is a list operation #670

Closed
elbosso opened this issue Jan 5, 2019 · 2 comments
Closed

Comments

@elbosso
Copy link

elbosso commented Jan 5, 2019

Description of the problem, including code/CLI snippet

I tried to emulate Githubs dynamic Badges using Apache, mod_python and python-gitlab. However, the building of a badge - for example showing the number of closed issues - is almost unbearably slow even when there are only 100 or so - using the naive approach to call list ant then count the returned elements (https://gist.github.com/elbosso/4f3bb0fb95dd1dc499cd46db422900bf).

However - the Gitlab API offers a possibility to count Objects - you simply have to do a fetch operation with pagination and setting the per_page parameter to 1 - the list operation still gives you a result and in that result there is the header X-Total - telling the total number of matching items for the given query. So we have an operation counting items matching a query that runs in constant time.

Example with curl:

 curl -i --header 'Private-Token: xxxx-xxxx-xxxxxxxxxx' 'http://<gitlab-host>/api/v4/projects/<project-id>/issues?state=closed&scope=all&per_page=1' 2>/dev/null

Expected Behavior

It would be nice if this kind of behaviour could be somehow added - maybe as add-on to the CRUD-Mixin?

I think, one would only need to support the v4 API here

Thanks for considering this - regards,

Juergen Key

@gpocentek
Copy link
Contributor

Hi @elbosso

You can use the as_list=False parameter to get the info you're looking for when listing items. See the pagination docs: https://python-gitlab.readthedocs.io/en/stable/api-usage.html#pagination

For now we only support GET requests but we could implement HEAD requests to only retrieve the metadata and not the objects.

@elbosso
Copy link
Author

elbosso commented Jan 9, 2019

Thank you very much - i did not see this in the documentation and dove head over heels into the api examples where this was not mentioned. It is exactly what i was looking for: my dynamic badges are now using as_list and the performance is marvelous. Thanks again - I am closing this issue now...

@elbosso elbosso closed this as completed Jan 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants