@@ -55,34 +55,36 @@ class ProjectService:
5555 def get_test_outcomes_with_rules (
5656 project : Project , rules : ListRules , filters : TestOutcomeItemFilters
5757 ) -> Page [TestOutcome ]:
58- clauses = [ TestOutcome .component .in_ (project .components )]
58+ query = TestOutcome .select ( TestOutcome ). where ( TestOutcome . component .in_ (project .components ))
5959 if rules .search is not None :
60- clauses .append ((TestOutcome .name ** f"%{ rules .search } %" ) | (TestOutcome .description ** f"%{ rules .search } %" ))
60+ query = query .where (
61+ ((TestOutcome .name ** f"%{ rules .search } %" ) | (TestOutcome .description ** f"%{ rules .search } %" ))
62+ )
6163 if filters :
6264 if statuses := filters .statuses :
63- clauses . append (TestOutcome .status .in_ (statuses ))
65+ query = query . where (TestOutcome .status .in_ (statuses ))
6466 if component_ids := filters .component_ids :
65- clauses . append (TestOutcome .component << component_ids )
67+ query = query . where (TestOutcome .component << component_ids )
6668 if start_range_begin := filters .start_range_begin :
67- clauses . append (TestOutcome .start_time >= start_range_begin )
69+ query = query . where (TestOutcome .start_time >= start_range_begin )
6870 if start_range_end := filters .start_range_end :
69- clauses . append (TestOutcome .start_time < start_range_end )
71+ query = query . where (TestOutcome .start_time < start_range_end )
7072 if end_range_begin := filters .end_range_begin :
71- clauses . append (TestOutcome .end_time >= end_range_begin )
73+ query = query . where (TestOutcome .end_time >= end_range_begin )
7274 if end_range_end := filters .end_range_end :
73- clauses . append (TestOutcome .end_time < end_range_end )
75+ query = query . where (TestOutcome .end_time < end_range_end )
7476 if run_ids := filters .run_ids :
75- clauses . append (TestOutcome .run .in_ (run_ids ))
77+ query = query . where (TestOutcome .run .in_ (run_ids ))
7678 if instance_ids := filters .instance_ids :
77- clauses .append (InstancesInstanceSets .instance .in_ (instance_ids ))
79+ instance_set_subquery = (
80+ InstanceSet .select (InstanceSet .id )
81+ .join (InstancesInstanceSets )
82+ .where (InstancesInstanceSets .instance .in_ (instance_ids ))
83+ )
84+ query = query .where (TestOutcome .instance_set .in_ (instance_set_subquery ))
7885 if key := filters .key :
79- clauses . append (TestOutcome .key == key )
86+ query = query . where (TestOutcome .key == key )
8087
81- # If filtering on instance_ids we need to join the InstanceSet tables
82- if filters and filters .instance_ids :
83- query = TestOutcome .select (TestOutcome ).join (InstanceSet ).join (InstancesInstanceSets ).where (* clauses )
84- else :
85- query = TestOutcome .select (TestOutcome ).where (* clauses )
8688 return Page [TestOutcome ].get_paginated_results (query , TestOutcome .start_time , rules )
8789
8890 @staticmethod
0 commit comments