From 15d42e717cf9c99bc579b58821077d6c5a0d5377 Mon Sep 17 00:00:00 2001 From: Kyle Sferrazza Date: Mon, 5 Oct 2020 18:46:03 -0400 Subject: [PATCH 1/3] Do not sync course registrations on login This may be convenient, but became a performance issue. Registrations can still be synced via the red `Sync` button for the course. --- lib/bottlenose.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bottlenose.rb b/lib/bottlenose.rb index 18498d20a..49a7fef26 100644 --- a/lib/bottlenose.rb +++ b/lib/bottlenose.rb @@ -19,7 +19,6 @@ def sync_courses hg_course.last_sync = DateTime.now hg_course.active = true hg_course.save! - sync_course_regs(hg_course) end end end From 6d82d457bc3fdceee70d65a2ec5ca9ab77a09d31 Mon Sep 17 00:00:00 2001 From: Kyle Sferrazza Date: Mon, 5 Oct 2020 18:56:58 -0400 Subject: [PATCH 2/3] Sync course regs on login if course has no users --- lib/bottlenose.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottlenose.rb b/lib/bottlenose.rb index 49a7fef26..a300e8ff1 100644 --- a/lib/bottlenose.rb +++ b/lib/bottlenose.rb @@ -19,6 +19,7 @@ def sync_courses hg_course.last_sync = DateTime.now hg_course.active = true hg_course.save! + sync_course_regs(hg_course) if hg_course.all_users.empty? end end end From 55e926923e2ac104b7820efd912489ade5a39d6f Mon Sep 17 00:00:00 2001 From: Kyle Sferrazza Date: Mon, 5 Oct 2020 19:13:34 -0400 Subject: [PATCH 3/3] update course last_sync only on registration sync --- app/models/course.rb | 4 ++++ lib/bottlenose.rb | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index 3a0fd3568..5faf5aa0a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -40,6 +40,10 @@ def all_users User.where(id: staff_ids + professor_ids + student_ids) end + def empty? + all_users.empty? + end + def has_staff? staff_registrations.exists? end diff --git a/lib/bottlenose.rb b/lib/bottlenose.rb index a300e8ff1..16a250cbb 100644 --- a/lib/bottlenose.rb +++ b/lib/bottlenose.rb @@ -16,15 +16,15 @@ def sync_courses hg_course = Course.find_or_initialize_by(bottlenose_id: active_course['id']) hg_course.title = active_course['name'] - hg_course.last_sync = DateTime.now hg_course.active = true hg_course.save! - sync_course_regs(hg_course) if hg_course.all_users.empty? + sync_course_regs(hg_course) if hg_course.empty? end end end def sync_course_regs(course) + course.update(:last_sync, DateTime.now) got = bottlenose_get("/api/courses/#{course.bottlenose_id}/registrations") got.each do |sec_id, sec_obj| sec = course.sections.find_or_initialize_by(bottlenose_id: sec_id)