@@ -184,20 +184,19 @@ def _collect_context(self):
184184 self .doc_aliases = DocAlias .objects .filter (docs = self .doc ).values_list ("name" , flat = True )
185185
186186 # This data is collected as a dict, keys being person IDs, values being numbers/objects.
187+ self .rotation_index = {p .pk : i for i , p in enumerate (self .rotation_list )}
187188 self .reviewer_settings = self ._reviewer_settings_for_person_ids (self .possible_person_ids )
188189 self .days_needed_for_reviewers = days_needed_to_fulfill_min_interval_for_reviewers (self .team )
189- self .rotation_index = {p .pk : i for i , p in enumerate (self .rotation_list )}
190+ self .connections = self ._connections_with_doc (self .doc , self .possible_person_ids )
191+ self .unavailable_periods = current_unavailable_periods_for_reviewers (self .team )
192+ self .assignment_data_for_reviewers = latest_review_assignments_for_reviewers (self .team )
193+ self .unavailable_periods = current_unavailable_periods_for_reviewers (self .team )
190194
191195 # This data is collected as a set of person IDs.
192196 self .has_completed_review_previous = self ._persons_with_previous_review (self .review_req , self .possible_person_ids , 'completed' )
193197 self .has_rejected_review_previous = self ._persons_with_previous_review (self .review_req , self .possible_person_ids , 'rejected' )
194198 self .wish_to_review = set (ReviewWish .objects .filter (team = self .team , person__in = self .possible_person_ids ,
195199 doc = self .doc ).values_list ("person" , flat = True ))
196-
197- self .connections = self ._connections_with_doc (self .doc , self .possible_person_ids )
198- self .unavailable_periods = current_unavailable_periods_for_reviewers (self .team )
199- self .assignment_data_for_reviewers = latest_review_assignments_for_reviewers (self .team )
200- self .unavailable_periods = current_unavailable_periods_for_reviewers (self .team )
201200
202201 def determine_ranking (self ):
203202 """
@@ -232,7 +231,7 @@ def add_boolean_score(direction, expr, explanation=None):
232231 if email .person_id not in self .rotation_index :
233232 return
234233
235- # If a reviewer is unavailable, they are ignored.
234+ # If a reviewer is unavailable at the moment , they are ignored.
236235 periods = self .unavailable_periods .get (email .person_id , [])
237236 unavailable_at_the_moment = periods and not (
238237 email .person_id in self .has_completed_review_previous and
@@ -265,12 +264,12 @@ def format_period(p):
265264 if days_needed > 0 :
266265 explanations .append ("max frequency exceeded, ready in {} {}" .format (days_needed ,
267266 "day" if days_needed == 1 else "days" ))
268- # skip next
267+ # skip next value
269268 scores .append (- settings .skip_next )
270269 if settings .skip_next > 0 :
271270 explanations .append ("skip next {}" .format (settings .skip_next ))
272271
273- # index
272+ # index in the default rotation order
274273 index = self .rotation_index .get (email .person_id , 0 )
275274 scores .append (- index )
276275 explanations .append ("#{}" .format (index + 1 ))
@@ -375,21 +374,21 @@ def default_reviewer_rotation_list(self, include_unavailable=False, dont_skip_pe
375374 reviewers .sort (key = lambda p : p .last_name ())
376375 next_reviewer_index = 0
377376
378- # now to figure out where the rotation is currently at
379- saved_reviewer = NextReviewerInTeam .objects .filter (team = self .team ).select_related ("next_reviewer" ).first ()
380- if saved_reviewer :
381- n = saved_reviewer .next_reviewer
377+ next_reviewer_in_team = NextReviewerInTeam .objects .filter (team = self .team ).select_related ("next_reviewer" ).first ()
378+ if next_reviewer_in_team :
379+ next_reviewer = next_reviewer_in_team .next_reviewer
382380
383- if n not in reviewers :
384- # saved reviewer might not still be here, if not just
385- # insert and use that position (Python will wrap around,
381+ if next_reviewer not in reviewers :
382+ # If the next reviewer is no longer on the team,
383+ # advance to the person that would be after them in
384+ # the rotation. (Python will wrap around,
386385 # so no harm done by using the index on the original list
387386 # afterwards)
388- reviewers_with_next = reviewers [:] + [n ]
387+ reviewers_with_next = reviewers [:] + [next_reviewer ]
389388 reviewers_with_next .sort (key = lambda p : p .last_name ())
390- next_reviewer_index = reviewers_with_next .index (n )
389+ next_reviewer_index = reviewers_with_next .index (next_reviewer )
391390 else :
392- next_reviewer_index = reviewers .index (n )
391+ next_reviewer_index = reviewers .index (next_reviewer )
393392
394393 rotation_list = reviewers [next_reviewer_index :] + reviewers [:next_reviewer_index ]
395394
@@ -418,7 +417,7 @@ def default_reviewer_rotation_list(self, include_unavailable=False, dont_skip_pe
418417 assignments = ReviewAssignment .objects .filter (
419418 review_request__team = self .team ,
420419 state__in = ['accepted' , 'assigned' , 'completed' ],
421- ).order_by ('assigned_on' )
420+ ).order_by ('assigned_on' ). select_related ( 'reviewer' )
422421
423422 reviewers_with_assignment = [assignment .reviewer .person for assignment in assignments ]
424423 reviewers_without_assignment = set (reviewers ) - set (reviewers_with_assignment )
@@ -433,9 +432,9 @@ def default_reviewer_rotation_list(self, include_unavailable=False, dont_skip_pe
433432 return rotation_list
434433
435434 def return_reviewer_to_top_rotation (self , reviewer_person ):
436- # Reviewer rotation for this policy ignored rejected/withdrawn
435+ # Reviewer rotation for this policy ignores rejected/withdrawn
437436 # reviews, so it automatically adjusts the position of someone
438- # who rejected a review and no action is needed.
437+ # who rejected a review and no further action is needed.
439438 pass
440439
441440
0 commit comments