Skip to content

Commit bd6988d

Browse files
djangolivogiorgis
andauthored
fix: remove useless loops (#8804)
* fix: remove useless loops * refacto: keep only the manifests for the dates that interest us * fix: remove more useless loops --------- Co-authored-by: Olivier Giorgis <[email protected]>
1 parent 39e8403 commit bd6988d

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def mock_summary_groups_request(monkeypatch):
988988
Mock get_summary_groups()
989989
"""
990990

991-
def _fetch_summary_groups(start_day, end_day):
991+
def _fetch_summary_groups(days):
992992
tests_folder = os.path.dirname(__file__)
993993
file_name = "summary_groups.json"
994994
data_path = os.path.join(tests_folder, "sample_data", file_name)

tests/intermittents_commenter/expected_comment.text

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is the #1 most frequent failure this week.
77
## Table
88
| |**no_variant**|**socketprocess_networking**|**spi-nw**|
99
|---|:-:|:-:|:-:|
10-
|**macosx1015-x86_64/debug**| | |1|
10+
|**macosx1015-x86_64/debug**| | |1/22|
1111

1212
## For more details, see:
1313
https://treeherder.mozilla.org/intermittent-failures/bugdetails?bug=1&startday=2022-05-09&endday=2025-05-10&tree=all

tests/intermittents_commenter/expected_comment_with_5_failures.text

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ This is the #1 most frequent failure this week.
77
## Table
88
| |**a11y_checks+swgl**|**no_variant**|**socketprocess_networking**|**spi-nw**|**swgl**|
99
|---|:-:|:-:|:-:|:-:|:-:|
10-
|**linux1804-x86_64/debug**| |1| |2| |
11-
|**macosx1015-x86_64/debug**| | | |2| |
10+
|**linux1804-x86_64/debug**| |1| |2/92| |
11+
|**macosx1015-x86_64/debug**| | | |2/22| |
1212

1313
## For more details, see:
1414
https://treeherder.mozilla.org/intermittent-failures/bugdetails?bug=1&startday=2022-05-09&endday=2025-05-10&tree=all

treeherder/intermittents_commenter/commenter.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ def generate_bug_changes(self, startday, endday, alt_startday, alt_endday):
7878
for bugs whose total number of daily or weekly occurrences meet
7979
the appropriate threshold) and potentially an updated whiteboard
8080
or priority status."""
81+
days = [startday]
82+
if self.weekly_mode:
83+
days = [
84+
(datetime.strptime(startday, "%Y-%m-%d") + timedelta(days=i)).strftime("%Y-%m-%d")
85+
for i in range(7)
86+
]
8187

8288
bug_ids, bugs = self.get_bugs(startday, endday)
8389
option_collection_map = OptionCollection.objects.get_option_collection_map()
84-
bug_map = self.build_bug_map(bugs, option_collection_map, startday, endday)
90+
bug_map = self.build_bug_map(bugs, option_collection_map, days)
8591

8692
alt_date_bug_totals = self.get_alt_date_bug_totals(alt_startday, alt_endday, bug_ids)
8793

@@ -388,32 +394,26 @@ def get_bug_run_info(self, bug):
388394
info.build_type = "unknown build"
389395
return info
390396

391-
def get_task_labels_and_count(self, manifest, start_day, end_day):
397+
def get_task_labels_and_count(self, manifest, days, job_name):
392398
tasks_and_count = {}
393399
summary_groups = (
394-
fetch.fetch_summary_groups(start_day, end_day)
395-
if self.summary_groups is None
396-
else self.summary_groups
400+
fetch.fetch_summary_groups(days) if self.summary_groups is None else self.summary_groups
397401
)
398-
days = [start_day]
399-
if self.weekly_mode:
400-
for j in range(6):
401-
jj = datetime.strptime(days[-1], "%Y-%m-%d") + timedelta(days=1)
402-
days.append(jj.strftime("%Y-%m-%d"))
403402
for day in days:
404403
if day not in summary_groups:
405404
continue
406405
all_task_labels = summary_groups[day]["job_type_names"]
407406
for tasks_by_manifest in summary_groups[day]["manifests"]:
408-
for man, tasks in tasks_by_manifest.items():
409-
if manifest == man:
410-
for task_index, _, _, count in tasks:
411-
task_label = all_task_labels[task_index]
407+
if manifest in tasks_by_manifest:
408+
for task_index, _, _, count in tasks_by_manifest[manifest]:
409+
task_label = all_task_labels[task_index]
410+
if task_label == job_name:
412411
tasks_and_count.setdefault(task_label, 0)
413412
tasks_and_count[task_label] += count
414-
return tasks_and_count
413+
break
414+
return tasks_and_count.get(job_name, 0)
415415

416-
def build_bug_map(self, bugs, option_collection_map, start_day, end_day):
416+
def build_bug_map(self, bugs, option_collection_map, days):
417417
"""Build bug_map
418418
eg:
419419
{
@@ -452,15 +452,10 @@ def build_bug_map(self, bugs, option_collection_map, start_day, end_day):
452452
if test_name:
453453
manifest = all_tests[test_name][0]
454454
if manifest:
455-
"""
456-
# Bug 1972307 - disabled due to no comments
457-
tasks_count = self.get_task_labels_and_count(manifest, start_day, end_day)
458455
job_name = bug["job__signature__job_type_name"]
459-
for task_name, count in tasks_count.items():
460-
if task_name == job_name or task_name == job_name.rsplit("-", 1)[0]:
461-
run_count = count
462-
break
463-
"""
456+
if len(job_name.rsplit("-", 1)) == 2 and job_name.rsplit("-", 1)[1].isdigit():
457+
job_name = job_name.rsplit("-", 1)[0]
458+
run_count = self.get_task_labels_and_count(manifest, days, job_name)
464459
testrun_matrix = (
465460
fetch.fetch_testrun_matrix()
466461
if self.testrun_matrix is None

treeherder/intermittents_commenter/fetch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def fetch_testrun_matrix():
2424
return response.json()
2525

2626

27-
def fetch_summary_groups(start_day, end_day):
27+
def fetch_summary_groups(days):
2828
testrun_info_url = f"{firefoxci_artefact_api_url}/test-run-info.json"
2929
response = requests.get(testrun_info_url, headers={"User-agent": "mach-test-info/1.0"})
30-
return response.json()
30+
summary_groups = response.json()
31+
return {key: summary_groups[key] for key in days}

0 commit comments

Comments
 (0)