99 Avg ,
1010 F ,
1111 Q ,
12+ QuerySet ,
1213 Sum ,
1314 Value ,
1415)
@@ -299,6 +300,17 @@ def compare(row: TestResultsRow) -> int:
299300 return rows [left :]
300301
301302
303+ def get_relevant_totals (
304+ repoid : int , branch : str | None , since : dt .datetime
305+ ) -> QuerySet :
306+ if branch :
307+ return DailyTestRollup .objects .filter (
308+ repoid = repoid , date__gt = since , branch = branch
309+ )
310+ else :
311+ return DailyTestRollup .objects .filter (repoid = repoid , date__gt = since )
312+
313+
302314def generate_test_results (
303315 ordering : str ,
304316 ordering_direction : str ,
@@ -342,7 +354,7 @@ def generate_test_results(
342354 test_ids : set [str ] | None = None
343355
344356 if term is not None :
345- totals = DailyTestRollup . objects . filter (repoid = repoid , date__gt = since )
357+ totals = get_relevant_totals (repoid , branch , since )
346358
347359 totals = totals .filter (test__name__icontains = term ).values ("test_id" )
348360
@@ -358,19 +370,21 @@ def generate_test_results(
358370 test_ids = test_ids & filtered_test_ids if test_ids else filtered_test_ids
359371
360372 if parameter is not None :
373+ totals = get_relevant_totals (repoid , branch , since )
361374 match parameter :
362375 case GENERATE_TEST_RESULT_PARAM .FLAKY :
363- flakes = Flake .objects .filter (
364- Q (repository_id = repoid )
365- & (Q (end_date__date__isnull = True ) | Q (end_date__date__gt = since ))
376+ flaky_test_ids = (
377+ totals .values ("test" )
378+ .annotate (flaky_fail_count_sum = Sum ("flaky_fail_count" ))
379+ .filter (flaky_fail_count_sum__gt = 0 )
380+ .values ("test_id" )
366381 )
382+ flaky_test_id_set = {test ["test_id" ] for test in flaky_test_ids }
367383
368- flaky_test_ids = set ([ flake . test_id for flake in flakes ])
369-
370- test_ids = test_ids & flaky_test_ids if test_ids else flaky_test_ids
384+ test_ids = (
385+ test_ids & flaky_test_id_set if test_ids else flaky_test_id_set
386+ )
371387 case GENERATE_TEST_RESULT_PARAM .FAILED :
372- totals = DailyTestRollup .objects .filter (repoid = repoid , date__gt = since )
373-
374388 failed_test_ids = (
375389 totals .values ("test" )
376390 .annotate (fail_count_sum = Sum ("fail_count" ))
@@ -383,8 +397,6 @@ def generate_test_results(
383397 test_ids & failed_test_id_set if test_ids else failed_test_id_set
384398 )
385399 case GENERATE_TEST_RESULT_PARAM .SKIPPED :
386- totals = DailyTestRollup .objects .filter (repoid = repoid , date__gt = since )
387-
388400 skipped_test_ids = (
389401 totals .values ("test" )
390402 .annotate (
@@ -401,8 +413,6 @@ def generate_test_results(
401413 test_ids & skipped_test_id_set if test_ids else skipped_test_id_set
402414 )
403415 case GENERATE_TEST_RESULT_PARAM .SLOWEST :
404- totals = DailyTestRollup .objects .filter (repoid = repoid , date__gt = since )
405-
406416 num_tests = totals .distinct ("test_id" ).count ()
407417
408418 slowest_test_ids = (
0 commit comments