fix: skip course_meeting churn when schedule unchanged#405
Conversation
📝 WalkthroughWalkthroughThe meeting comparison logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ferry/database/sync_db_courses.py (1)
472-482: Comparison logic correctly handles both modes.The conditional comparison appropriately:
- Compares only structural columns (
start_time,end_time,days_of_week) when freezing locations, soNULLvs actuallocation_idvalues don't trigger unnecessary churn- Falls back to full
equals()when not freezingOne minor readability suggestion: consider defining
structural_colsalongsidesort_cols(lines 449-453) to make their relationship explicit and reduce nesting.💡 Optional refactor for clarity
# With freeze_locations, new rows have null location_id but DB rows have IDs; a # full-frame equals() would mark every course changed. Compare times + days only. - sort_cols = ( - ["start_time", "end_time", "days_of_week"] - if freeze_locations - else ["start_time", "end_time", "location_id"] - ) + if freeze_locations: + sort_cols = ["start_time", "end_time", "days_of_week"] + compare_cols = ["start_time", "end_time", "days_of_week"] + else: + sort_cols = ["start_time", "end_time", "location_id"] + compare_cols = None # use full DataFrame comparison old_meetings = ( old_subset.iloc[:] .sort_values(sort_cols) .reset_index(drop=True) ) new_meetings = ( new_subset.iloc[:] .sort_values(sort_cols) .reset_index(drop=True) ) # Check if any old meetings have missing location IDs - if so, treat as changed if old_meetings["location_id"].apply(safe_isna).any(): changed_course_ids.add(course_id) continue # Compare the meeting sets (excluding course_id) try: - if freeze_locations: - structural_cols = ["start_time", "end_time", "days_of_week"] - if not old_meetings[structural_cols].equals( - new_meetings[structural_cols] - ): - changed_course_ids.add(course_id) - elif not old_meetings.equals(new_meetings): + if compare_cols is not None: + is_equal = old_meetings[compare_cols].equals(new_meetings[compare_cols]) + else: + is_equal = old_meetings.equals(new_meetings) + if not is_equal: changed_course_ids.add(course_id) except (ValueError, TypeError):🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ferry/database/sync_db_courses.py` around lines 472 - 482, Move the structural_cols definition up next to sort_cols to improve readability: declare structural_cols = ["start_time", "end_time", "days_of_week"] alongside the existing sort_cols definition, then reuse that variable in the comparison block that checks freeze_locations (the block that currently sets structural_cols inside the if). Keep the existing comparison logic using old_meetings[structural_cols].equals(new_meetings[structural_cols]) and the else branch that uses old_meetings.equals(new_meetings), and leave the exception handler adding course_id to changed_course_ids unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ferry/database/sync_db_courses.py`:
- Around line 472-482: Move the structural_cols definition up next to sort_cols
to improve readability: declare structural_cols = ["start_time", "end_time",
"days_of_week"] alongside the existing sort_cols definition, then reuse that
variable in the comparison block that checks freeze_locations (the block that
currently sets structural_cols inside the if). Keep the existing comparison
logic using old_meetings[structural_cols].equals(new_meetings[structural_cols])
and the else branch that uses old_meetings.equals(new_meetings), and leave the
exception handler adding course_id to changed_course_ids unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 78d5cf26-320c-4ef7-afcf-3cf32b016fa5
📒 Files selected for processing (1)
ferry/database/sync_db_courses.py
should speed up ferry run when locations are frozen
Summary by CodeRabbit