@@ -187,32 +187,25 @@ def _compute_run_status(t_prog, results_by_test, files_by_test_and_rt, t_id, exp
187187 return 'incomplete'
188188
189189
190- def batch_get_run_data (tests : list ) -> tuple :
191- """
192- Batch compute derive_run_status and get_run_timestamps for a list of tests.
193-
194- Returns (statuses_dict, timestamps_dict)
195- """
196- if not tests :
197- return {}, {}
198-
199- test_ids = [t .id for t in tests ]
200-
201- # Preload TestProgress
190+ def _preload_test_progress (test_ids ):
202191 all_progress = TestProgress .query .filter (TestProgress .test_id .in_ (
203192 test_ids )).order_by (TestProgress .id .asc ()).all ()
204193 progress_by_test = {tid : [] for tid in test_ids }
205194 for p in all_progress :
206195 progress_by_test [p .test_id ].append (p )
196+ return progress_by_test
197+
207198
208- # Preload TestResult
199+ def _preload_test_results ( test_ids ):
209200 all_results = TestResult .query .filter (
210201 TestResult .test_id .in_ (test_ids )).all ()
211202 results_by_test = {tid : [] for tid in test_ids }
212203 for r in all_results :
213204 results_by_test [r .test_id ].append (r )
205+ return results_by_test
214206
215- # Preload TestResultFile
207+
208+ def _preload_test_result_files (test_ids ):
216209 from sqlalchemy .orm import joinedload
217210
218211 from mod_regression .models import RegressionTestOutput
@@ -226,22 +219,44 @@ def batch_get_run_data(tests: list) -> tuple:
226219 if key not in files_by_test_and_rt :
227220 files_by_test_and_rt [key ] = []
228221 files_by_test_and_rt [key ].append (f )
222+ return files_by_test_and_rt
223+
229224
230- # Preload expected outputs (RegressionTestOutput) for missing-output detection
225+ def _preload_expected_outputs ( results_by_test , test_ids ):
231226 all_rt_ids = set ()
232227 for tid in test_ids :
233228 for r in results_by_test .get (tid , []):
234229 all_rt_ids .add (r .regression_test_id )
235230
236- expected_outputs_by_rt = {}
237- if all_rt_ids :
238- from collections import defaultdict
239- all_expected = RegressionTestOutput .query .filter (
240- RegressionTestOutput .regression_id .in_ (all_rt_ids )
241- ).all ()
242- expected_outputs_by_rt = defaultdict (list )
243- for rto in all_expected :
244- expected_outputs_by_rt [rto .regression_id ].append (rto )
231+ if not all_rt_ids :
232+ return {}
233+
234+ from collections import defaultdict
235+
236+ from mod_regression .models import RegressionTestOutput
237+ all_expected = RegressionTestOutput .query .filter (
238+ RegressionTestOutput .regression_id .in_ (all_rt_ids )
239+ ).all ()
240+ expected_outputs_by_rt = defaultdict (list )
241+ for rto in all_expected :
242+ expected_outputs_by_rt [rto .regression_id ].append (rto )
243+ return expected_outputs_by_rt
244+
245+
246+ def batch_get_run_data (tests : list ) -> tuple :
247+ """
248+ Batch compute derive_run_status and get_run_timestamps for a list of tests.
249+
250+ Returns (statuses_dict, timestamps_dict)
251+ """
252+ if not tests :
253+ return {}, {}
254+
255+ test_ids = [t .id for t in tests ]
256+ progress_by_test = _preload_test_progress (test_ids )
257+ results_by_test = _preload_test_results (test_ids )
258+ files_by_test_and_rt = _preload_test_result_files (test_ids )
259+ expected_outputs_by_rt = _preload_expected_outputs (results_by_test , test_ids )
245260
246261 statuses = {}
247262 timestamps_dict = {}
0 commit comments