Added pagination to fetch_all method #345
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Zou has the ability to provide pagination, but Gazu ignores this functionality at the moment.
I used the get_preview_files_for_project method exposed at the /data/preview-files webhook to fetch all preview files, it becomes impossible to fetch these records. Zou yields a 502 Gateway Error. I am aware that this is an absurd query, but it's a good benchmark.
Pagination is available in Zou: https://github.com/cgwire/zou/blob/8be5dfd1744115ec08eb0c5668db62e1854ebbed/zou/app/services/files_service.py#L902
Solution
I added the "pagination" parameter to "fetch_all", which will cause the method to handle the query in slices of 100.
gazu.client.fetch_all('preview-files',
params=project_id, paginated=True)`This solution also works for Persons, Tasks and other resources that inherit from the ArgsMixin in Zou.
All tests ran green. I think it would be interesting to make this option the default at some point, but will leave it for TD's that need the functionality (and know what they're doing) for now.
Note: Also adding .idea to the .gitignore to support PyCharm (if you'd like to have the run config for the unit tests, let me know.)