Skip to content

Commit 14f5432

Browse files
committed
bugs: batch query for bugs with many packages
Resolves: #214 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 319e413 commit 14f5432

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

src/pkgdev/scripts/pkgdev_bugs.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -688,29 +688,37 @@ def merge_stabilization_groups(self):
688688
self.merge_nodes(mergable)
689689

690690
def scan_existing_bugs(self, api_key: str):
691-
params = urlencode(
692-
{
693-
"Bugzilla_api_key": api_key,
694-
"include_fields": "id,cf_stabilisation_atoms,summary",
695-
"component": "Stabilization",
696-
"resolution": "---",
697-
"f1": "cf_stabilisation_atoms",
698-
"o1": "anywords",
699-
"v1": {pkg[0].unversioned_atom for node in self.nodes for pkg in node.pkgs},
700-
},
701-
doseq=True,
702-
)
703-
request = urllib.Request(
704-
url="https://bugs.gentoo.org/rest/bug?" + params,
705-
method="GET",
706-
headers={
707-
"Content-Type": "application/json",
708-
"Accept": "application/json",
709-
},
710-
)
711-
with urllib.urlopen(request, timeout=30) as response:
712-
reply = json.loads(response.read().decode("utf-8"))
713-
for bug in reply["bugs"]:
691+
# Paginate the search request with batches of 100 items to avoid HTTP 414 errors
692+
all_packages = list({pkg[0].unversioned_atom for node in self.nodes for pkg in node.pkgs})
693+
batch_size = 100
694+
all_bugs = []
695+
696+
for i in range(0, len(all_packages), batch_size):
697+
params = urlencode(
698+
{
699+
"Bugzilla_api_key": api_key,
700+
"include_fields": "id,cf_stabilisation_atoms,summary",
701+
"component": "Stabilization",
702+
"resolution": "---",
703+
"f1": "cf_stabilisation_atoms",
704+
"o1": "anywords",
705+
"v1": all_packages[i : i + batch_size],
706+
},
707+
doseq=True,
708+
)
709+
request = urllib.Request(
710+
url="https://bugs.gentoo.org/rest/bug?" + params,
711+
method="GET",
712+
headers={
713+
"Content-Type": "application/json",
714+
"Accept": "application/json",
715+
},
716+
)
717+
with urllib.urlopen(request, timeout=30) as response:
718+
reply = json.loads(response.read().decode("utf-8"))
719+
all_bugs.extend(reply.get("bugs", []))
720+
721+
for bug in all_bugs:
714722
bug_atoms = (
715723
parse_atom(line.split(" ", 1)[0]).unversioned_atom
716724
for line in map(str.strip, bug["cf_stabilisation_atoms"].splitlines())

0 commit comments

Comments
 (0)