@@ -101,13 +101,29 @@ def get_new_batch(self, name, **kwargs):
101101
102102 @api .depends ("job_ids.state" )
103103 def _compute_job_count (self ):
104+ grouped = self .env ["queue.job" ].read_group (
105+ [("job_batch_id" , "in" , self .ids )],
106+ ["job_batch_id" , "state" ],
107+ ["job_batch_id" , "state" ],
108+ lazy = False ,
109+ )
110+ counts = {}
111+ for g in grouped :
112+ batch_id = g ["job_batch_id" ][0 ]
113+ counts .setdefault (batch_id , {})
114+ counts [batch_id ][g ["state" ]] = g ["__count" ]
115+
104116 for rec in self :
105- jobs_by_state = rec .job_ids .grouped ("state" )
106- rec .job_count = len (rec .job_ids )
107- rec .failed_job_count = len (jobs_by_state .get ("failed" , []))
108- rec .finished_job_count = len (jobs_by_state .get ("done" , []))
109- rec .completeness = rec .finished_job_count / max (1 , rec .job_count )
110- rec .failed_percentage = rec .failed_job_count / max (1 , rec .job_count )
117+ by_state = counts .get (rec .id , {})
118+ total = sum (by_state .values ())
119+ done = by_state .get ("done" , 0 )
120+ failed = by_state .get ("failed" , 0 )
121+
122+ rec .job_count = total
123+ rec .failed_job_count = failed
124+ rec .finished_job_count = done
125+ rec .completeness = done / max (1 , total )
126+ rec .failed_percentage = failed / max (1 , total )
111127
112128 @api .model
113129 def _to_store_fnames (self ):
0 commit comments