@@ -55,36 +55,37 @@ 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 (
60+ query = query . where (
6161 ((TestOutcome .name ** f"%{ rules .search } %" ) | (TestOutcome .description ** f"%{ rules .search } %" ))
6262 )
63+
6364 if filters :
6465 if statuses := filters .statuses :
65- clauses . append (TestOutcome .status .in_ (statuses ))
66+ query = query . where (TestOutcome .status .in_ (statuses ))
6667 if component_ids := filters .component_ids :
67- clauses . append (TestOutcome .component << component_ids )
68+ query = query . where (TestOutcome .component << component_ids )
6869 if start_range_begin := filters .start_range_begin :
69- clauses . append (TestOutcome .start_time >= start_range_begin )
70+ query = query . where (TestOutcome .start_time >= start_range_begin )
7071 if start_range_end := filters .start_range_end :
71- clauses . append (TestOutcome .start_time < start_range_end )
72+ query = query . where (TestOutcome .start_time < start_range_end )
7273 if end_range_begin := filters .end_range_begin :
73- clauses . append (TestOutcome .end_time >= end_range_begin )
74+ query = query . where (TestOutcome .end_time >= end_range_begin )
7475 if end_range_end := filters .end_range_end :
75- clauses . append (TestOutcome .end_time < end_range_end )
76+ query = query . where (TestOutcome .end_time < end_range_end )
7677 if run_ids := filters .run_ids :
77- clauses . append (TestOutcome .run .in_ (run_ids ))
78+ query = query . where (TestOutcome .run .in_ (run_ids ))
7879 if instance_ids := filters .instance_ids :
79- clauses .append (InstancesInstanceSets .instance .in_ (instance_ids ))
80+ instance_set_subquery = (
81+ InstanceSet .select (InstanceSet .id )
82+ .join (InstancesInstanceSets )
83+ .where (InstancesInstanceSets .instance .in_ (instance_ids ))
84+ )
85+ query = query .where (TestOutcome .instance_set .in_ (instance_set_subquery ))
8086 if key := filters .key :
81- clauses . append (TestOutcome .key == key )
87+ query = query . where (TestOutcome .key == key )
8288
83- # If filtering on instance_ids we need to join the InstanceSet tables
84- if filters and filters .instance_ids :
85- query = TestOutcome .select (TestOutcome ).join (InstanceSet ).join (InstancesInstanceSets ).where (* clauses )
86- else :
87- query = TestOutcome .select (TestOutcome ).where (* clauses )
8889 return Page [TestOutcome ].get_paginated_results (query , TestOutcome .start_time , rules )
8990
9091 @staticmethod
0 commit comments