From 1d95fdb607b977b3e52227f0b6f62146687a9655 Mon Sep 17 00:00:00 2001 From: Fabio Lima Date: Sun, 24 May 2026 14:52:42 -0700 Subject: [PATCH] fix: simplify overlapping time slots logic --- app/models/facility_time_slot.rb | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/app/models/facility_time_slot.rb b/app/models/facility_time_slot.rb index 680c898..5aba2a6 100644 --- a/app/models/facility_time_slot.rb +++ b/app/models/facility_time_slot.rb @@ -43,23 +43,13 @@ def overlapping_time_slots return FacilityTimeSlot.none unless [from_hour, from_min, to_hour, to_min].all?(&:present?) start_i = (from_hour + (from_min/60r)).to_f - end_i = (to_hour + (to_min/60r)).to_f - - sql_start_i = Arel.sql("(from_hour + (from_min / 60.0))") - sql_end_i = Arel.sql("(to_hour + (to_min / 60.0))") - - query_sql = <<~SQL.squish - ( - SELECT ts.*, - #{sql_start_i} as start_i, - #{sql_end_i} as end_i - FROM facility_time_slots ts - WHERE (#{sql_start_i} <= #{end_i}) - AND (#{sql_end_i} >= #{start_i}) - ) as facility_time_slots - SQL - - FacilityTimeSlot.from(query_sql).where(id: siblings_time_slots) + end_i = (to_hour + (to_min/60r)).to_f + + siblings_time_slots.where( + "(from_hour + (from_min / 60.0)) <= ? AND (to_hour + (to_min / 60.0)) >= ?", + end_i, + start_i + ) end private