-
Notifications
You must be signed in to change notification settings - Fork 166
Improve pagination handling in Confluence API client #3321
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,23 +259,31 @@ async def paginated_api_call(self, url_name, **url_kwargs): | |
Yields: | ||
response: JSON response. | ||
""" | ||
url = os.path.join(self.host_url, URLS[url_name].format(**url_kwargs)) | ||
base_url = os.path.join(self.host_url, URLS[url_name].format(**url_kwargs)) | ||
start = 0 | ||
|
||
while True: | ||
try: | ||
url = f"{base_url}&start={start}" | ||
self._logger.debug(f"Starting pagination for API endpoint {url}") | ||
response = await self.api_call(url=url) | ||
json_response = await response.json() | ||
|
||
links = json_response.get("_links") | ||
yield json_response | ||
if links.get("next") is None: | ||
if links.get("next"): | ||
url = os.path.join( | ||
self.host_url, | ||
links.get("next")[1:], | ||
) | ||
elif json_response.get("start") + json_response.get("size") < json_response.get("totalSize"): | ||
start = json_response.get("start") + json_response.get("size") | ||
url = f"{base_url}&start={start}" | ||
else: | ||
return | ||
url = os.path.join( | ||
self.host_url, | ||
links.get("next")[1:], | ||
) | ||
except Exception as exception: | ||
self._logger.warning( | ||
f"Skipping data for type {url_name} from {url}. Exception: {exception}." | ||
f"Skipping data for type {url_name} from {base_url}. Exception: {exception}." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd actually still want to log out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the only reason I switched this to base_url is because it's possible that url does not exist if try step fails (or at least so I think it could happen) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! Ok, hadn't caught this, but I think |
||
) | ||
break | ||
|
||
|
@@ -984,8 +992,7 @@ async def search_by_query(self, query): | |
# entity can be space or content | ||
entity_details = entity.get(SPACE) or entity.get(CONTENT) | ||
|
||
if ( | ||
entity_details.get("type", "") == "attachment" | ||
if not entity_details or (entity_details.get("type", "") == "attachment" | ||
and entity_details.get("container", {}).get("title") is None | ||
): | ||
continue | ||
|
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.
This line probably needs to be outside of the
while True
, otherwise it'll overwrite the last iteration's attempts to set the URL to the "next" link, if that strategy was used.