Skip to content

Commit 093e499

Browse files
committed
review: Parallelize pending reviews update
Signed-off-by: Mathieu Dubois-Briand <[email protected]>
1 parent 8170e4b commit 093e499

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

swattool/review.py

+29-25
Original file line numberDiff line numberDiff line change
@@ -446,36 +446,40 @@ def batch_review_failures(builds: list[swatbuild.Build],
446446
def get_new_reviews() -> dict[tuple[swatbotrest.TriageStatus, Any],
447447
list[userdata.Triage]]:
448448
"""Get a list of new reviews waiting to be published on swatbot server."""
449+
450+
def update_userinfo(userinfo):
451+
for triage in userinfo.triages:
452+
status = triage.status
453+
comment = triage.comment
454+
if not status:
455+
continue
456+
457+
if not comment:
458+
logger.warning("Review for failure %s is missing comment: "
459+
"skipping", buildid)
460+
continue
461+
462+
def is_pending(failure_id):
463+
pol = swatbotrest.RefreshPolicy.FORCE
464+
failure = swatbotrest.get_stepfailure(failure_id,
465+
refresh_override=pol)
466+
return failure['attributes']['triage'] == 0
467+
468+
# Make sure failures are still pending
469+
triage.failures = {f for f in triage.failures if is_pending(f)}
470+
471+
if triage.failures:
472+
reviews.setdefault((status, comment), []).append(triage)
473+
449474
userinfos = userdata.UserInfos()
450475

451-
logger.info("Loading pending reviews...")
452476
reviews: dict[tuple[swatbotrest.TriageStatus, Any],
453477
list[userdata.Triage]] = {}
454-
with click.progressbar(userinfos.items()) as userinfos_progress:
455-
for buildid, userinfo in userinfos_progress:
456-
for triage in userinfo.triages:
457-
status = triage.status
458-
comment = triage.comment
459-
if not status:
460-
continue
461-
462-
if not comment:
463-
logger.warning("Review for failure %s is missing comment: "
464-
"skipping", buildid)
465-
continue
466-
467-
def is_pending(failure_id):
468-
pol = swatbotrest.RefreshPolicy.FORCE
469-
failure = swatbotrest.get_stepfailure(failure_id,
470-
refresh_override=pol)
471-
return failure['attributes']['triage'] == 0
472-
473-
# Make sure failures are still pending
474-
triage.failures = {f for f in triage.failures if is_pending(f)}
475-
476-
if triage.failures:
477-
reviews.setdefault((status, comment), []).append(triage)
478+
executor = utils.ExecutorWithProgress(8)
479+
for buildid, userinfo in userinfos.items():
480+
executor.submit("Updating pending review", update_userinfo, userinfo)
478481

482+
executor.run()
479483
userinfos.save()
480484

481485
return reviews

swattool/utils.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ def launch_in_system_defaultshow_in_less(text: str):
164164
class ExecutorWithProgress:
165165
"""Generate a thread pool executor with progress bar."""
166166

167-
def __init__(self):
168-
self.executor = concurrent.futures.ThreadPoolExecutor(
169-
min(16, os.cpu_count()))
170-
self.jobs = []
167+
def __init__(self, threads: Optional[int] = None):
168+
if threads is None:
169+
cpus = os.cpu_count()
170+
threads = min(16, cpus) if cpus else 16
171+
self.executor = concurrent.futures.ThreadPoolExecutor(threads)
172+
self.jobs: list[tuple[str, concurrent.futures.Future]] = []
171173

172174
def submit(self, name, *args, **kwargs):
173175
"""Submit a new job to the executor."""

0 commit comments

Comments
 (0)