From: Jacob Lifshay Date: Wed, 23 Aug 2023 00:49:10 +0000 (-0700) Subject: consolidate rpc requests for bug comments, hopefully speeding up code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=027929c3faac36eac283958bf727bf584ad6c47f;p=utils.git consolidate rpc requests for bug comments, hopefully speeding up code --- diff --git a/src/budget_sync/main.py b/src/budget_sync/main.py index a5ec9fa..35a480e 100644 --- a/src/budget_sync/main.py +++ b/src/budget_sync/main.py @@ -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)