Skip to content

Commit 6dc1850

Browse files
committed
Optimize get_all_attachment_contents to use less API calls
1 parent ea179f7 commit 6dc1850

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

atlassian/jira.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,27 @@ def get_all_attachment_contents(
403403
try:
404404
if path is None:
405405
path = os.getcwd()
406-
issue_id = self.issue(issue, fields="id")["id"]
406+
issue_data = self.issue(issue, fields="id,attachment")
407+
issue_id = issue_data["id"]
407408
attachment_name = f"{issue_id}_attachments.zip"
408409
file_path = os.path.join(path, attachment_name)
409410
if not overwrite and os.path.isfile(file_path):
410411
return file_path
411412

412-
attachments_metadata = self.get_attachments_ids_from_issue(issue)
413+
attachments_metadata = issue_data["fields"]["attachment"]
413414
if not attachments_metadata:
414415
return None
415416

416417
with zipfile.ZipFile(file_path, "w", compression=compression) as file:
417418
for meta in attachments_metadata:
418-
file.writestr(meta["filename"], self.get_attachment_content(meta["attachment_id"]))
419+
# stream download should not be used, as writestr expects full content with filename.
420+
content = self.get(
421+
meta["content"],
422+
not_json_response=True,
423+
absolute=True,
424+
headers={"Accept": "*/*"},
425+
)
426+
file.writestr(meta["filename"], content)
419427

420428
return file_path
421429

0 commit comments

Comments
 (0)