@@ -285,10 +285,12 @@ public function getQueryBuilder(): Builder
285
285
// Aggregate the latest review round number for the given assignment
286
286
->leftJoinSub (
287
287
DB ::table ('review_rounds ' , 'rr ' )
288
- ->select ('rr.submission_id ' )
288
+ ->select ([ 'rr.submission_id ' , ' rr.stage_id ' ] )
289
289
->selectRaw ('MAX(rr.round) as current_round ' )
290
- ->selectRaw ('MAX(rr.stage_id) as current_stage ' )
291
- ->groupBy ('rr.submission_id ' ),
290
+ ->groupBy (['rr.submission_id ' , 'rr.stage_id ' ])
291
+ // OMP has 2 review stages, must pick the latest on to determine the current review round correctly
292
+ ->havingRaw ('stage_id = MAX(rr.stage_id) ' )
293
+ ->distinct (),
292
294
'agrr ' ,
293
295
fn (JoinClause $ join ) => $ join ->on ('ra.submission_id ' , '= ' , 'agrr.submission_id ' )
294
296
)
@@ -315,7 +317,7 @@ public function getQueryBuilder(): Builder
315
317
$ q ->when ($ this ->isLastReviewRound || $ this ->isIncomplete , function (Builder $ q ) {
316
318
$ q
317
319
->whereColumn ('ra.round ' , '= ' , 'agrr.current_round ' ) // assignments from the last review round only
318
- ->whereColumn ('ra.stage_id ' , '= ' , 'agrr.current_stage ' ) // assignments for the current review stage only (for OMP)
320
+ ->whereColumn ('ra.stage_id ' , '= ' , 'agrr.stage_id ' ) // assignments for the current review stage only (for OMP)
319
321
->when (
320
322
$ this ->isIncomplete ,
321
323
fn (Builder $ q ) => $ q
@@ -454,14 +456,13 @@ public function getQueryBuilder(): Builder
454
456
->leftJoinSub (
455
457
DB ::table ('review_assignments as ramax ' )
456
458
->select (['ramax.submission_id ' , 'ramax.reviewer_id ' ])
457
- ->selectRaw ('MAX(ramax.round) as latest_round ' )
458
459
->selectRaw ('MAX(ramax.stage_id) as latest_stage ' )
459
460
->whereIn ('ramax.reviewer_id ' , $ this ->reviewerIds )
460
461
->groupBy (['ramax.submission_id ' , 'ramax.reviewer_id ' ]),
461
462
'agrmax ' ,
462
463
fn (JoinClause $ join ) => $ join ->on ('ra.submission_id ' , '= ' , 'agrmax.submission_id ' )
463
464
)
464
- ->whereColumn ('ra.round ' , 'agrmax.latest_round ' ) // assignments from the last review round per reviewer only
465
+ ->whereColumn ('ra.round ' , 'agrr.current_round ' ) // assignments from the last review round per reviewer only
465
466
->whereColumn ('ra.stage_id ' , 'agrmax.latest_stage ' ) // assignments for the current review stage only (for OMP)
466
467
)
467
468
);
0 commit comments