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

remove dead code in _fetch_pages #1870

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 74 additions & 80 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,94 +819,88 @@ def json_params() -> dict[str, Any]:
next_items_page = self._get_items_from_page(item_type, items_key, resource)
items = next_items_page

if True: # isinstance(resource, dict):
if isinstance(resource, dict):
total = resource.get("total")
total = int(total) if total is not None else total
# 'isLast' is the optional key added to responses in Jira Agile 6.7.6.
# So far not used in basic Jira API.
is_last = resource.get("isLast", False)
start_at_from_response = resource.get("startAt", 0)
max_results_from_response = resource.get("maxResults", 1)
else:
# if is a list
total = 1
is_last = True
start_at_from_response = 0
max_results_from_response = 1

# If maxResults evaluates as False, get all items in batches
if not maxResults:
page_size = max_results_from_response or len(items)
if batch_size is not None and page_size < batch_size:
self.log.warning(
"'batch_size' set to %s, but only received %s items in batch. Falling back to %s.",
batch_size,
page_size,
page_size,
)
page_start = (startAt or start_at_from_response or 0) + page_size
if (
async_class is not None
and not is_last
and (total is not None and len(items) < total)
):
async_fetches = []
future_session = async_class(
session=self._session, max_workers=async_workers
)
for start_index in range(page_start, total, page_size):
page_params = json_params()
page_params["startAt"] = start_index
page_params["maxResults"] = page_size
url = self._get_url(request_path)
r = (
future_session.post(url, data=json.dumps(page_params))
if use_post
else future_session.get(url, params=page_params)
)
async_fetches.append(r)
for future in async_fetches:
response = future.result()
resource = json_loads(response)
if resource:
next_items_page = self._get_items_from_page(
item_type, items_key, resource
)
items.extend(next_items_page)
while (
async_class is None
and not is_last
and (total is None or page_start < total)
and len(next_items_page) == page_size
):
page_params = (
json_params()
) # Hack necessary for mock-calls to not change
page_params["startAt"] = page_start
if isinstance(resource, dict):
total = resource.get("total")
total = int(total) if total is not None else total
# 'isLast' is the optional key added to responses in Jira Agile 6.7.6.
# So far not used in basic Jira API.
is_last = resource.get("isLast", False)
start_at_from_response = resource.get("startAt", 0)
max_results_from_response = resource.get("maxResults", 1)
else:
# if is a list
total = 1
is_last = True
start_at_from_response = 0
max_results_from_response = 1

# If maxResults evaluates as False, get all items in batches
if not maxResults:
page_size = max_results_from_response or len(items)
if batch_size is not None and page_size < batch_size:
self.log.warning(
"'batch_size' set to %s, but only received %s items in batch. Falling back to %s.",
batch_size,
page_size,
page_size,
)
page_start = (startAt or start_at_from_response or 0) + page_size
if (
async_class is not None
and not is_last
and (total is not None and len(items) < total)
):
async_fetches = []
future_session = async_class(
session=self._session, max_workers=async_workers
)
for start_index in range(page_start, total, page_size):
page_params = json_params()
page_params["startAt"] = start_index
page_params["maxResults"] = page_size

resource = self._get_json(
request_path, params=page_params, base=base, use_post=use_post
url = self._get_url(request_path)
r = (
future_session.post(url, data=json.dumps(page_params))
if use_post
else future_session.get(url, params=page_params)
)
async_fetches.append(r)
for future in async_fetches:
response = future.result()
resource = json_loads(response)
if resource:
next_items_page = self._get_items_from_page(
item_type, items_key, resource
)
items.extend(next_items_page)
page_start += page_size
else:
# if resource is an empty dictionary we assume no-results
break
while (
async_class is None
and not is_last
and (total is None or page_start < total)
and len(next_items_page) == page_size
):
page_params = (
json_params()
) # Hack necessary for mock-calls to not change
page_params["startAt"] = page_start
page_params["maxResults"] = page_size

resource = self._get_json(
request_path, params=page_params, base=base, use_post=use_post
)
if resource:
next_items_page = self._get_items_from_page(
item_type, items_key, resource
)
items.extend(next_items_page)
page_start += page_size
else:
# if resource is an empty dictionary we assume no-results
break

return ResultList(
items, start_at_from_response, max_results_from_response, total, is_last
)
else: # TODO: unreachable
# it seems that search_users can return a list() containing a single user!
return ResultList(
[item_type(self._options, self._session, resource)], 0, 1, 1, True
)
return ResultList(
items, start_at_from_response, max_results_from_response, total, is_last
)

def _get_items_from_page(
self,
Expand Down
Loading