consolidate rpc requests for bug comments, hopefully speeding up code
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 23 Aug 2023 00:49:10 +0000 (17:49 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 23 Aug 2023 00:49:10 +0000 (17:49 -0700)
src/budget_sync/main.py

index a5ec9faec6b136075222f5d7b2060a77e2742eb6..35a480e80a6acb07f28b34bd5bfc0da1218e9d57 100644 (file)
@@ -9,7 +9,7 @@ from bugzilla import Bugzilla
 import logging
 import argparse
 from pathlib import Path
-from budget_sync.util import all_bugs
+from budget_sync.util import all_bugs, tty_out
 from budget_sync.config import Config, ConfigParseError
 from budget_sync.budget_graph import BudgetGraph, PaymentSummary
 from budget_sync.write_budget_markdown import (write_budget_markdown,
@@ -157,6 +157,32 @@ def json_milestones(budget_graph: BudgetGraph, add_comments: bool,
                     output_dir: Path):
     """reports milestones as json format
     """
+    bug_comments_map = {}
+    if add_comments:
+        need_set = set()
+        bugzilla = None
+        for nodes in budget_graph.assigned_nodes_for_milestones.values():
+            for node in nodes:
+                need_set.add(node.bug.id)
+                bugzilla = node.bug.bugzilla
+        need_list = sorted(need_set)
+        total = len(need_list)
+        with tty_out() as term:
+            step = 100
+            i = 0
+            while i < total:
+                cur_need = need_list[i:i + step]
+                stop = i + len(cur_need)
+                print(f"loading comments {i}:{stop} of {total}",
+                      flush=True, file=term)
+                comments = bugzilla.get_comments(cur_need)['bugs']
+                if len(comments) < len(cur_need) and len(cur_need) > 1:
+                    step = max(1, step // 2)
+                    print(f"failed, trying smaller step of {step}",
+                          flush=True, file=term)
+                    continue
+                bug_comments_map.update(comments)
+                i += len(cur_need)
     for milestone, payments in budget_graph.milestone_payments.items():
         summary = PaymentSummary(payments)
         # and one to display people
@@ -196,7 +222,7 @@ def json_milestones(budget_graph: BudgetGraph, add_comments: bool,
             intro = []
             comment = "%s\n " % child.bug_url
             if add_comments:
-                comments = child.bug.getcomments()
+                comments = bug_comments_map[str(child.bug.id)]['comments']
                 comment += "\n%s" % comments[0]['text']
             intro.append(comment)
             # print (description, intro)