From 9a84545cfe7b0c9b1440c837ab743213201591d8 Mon Sep 17 00:00:00 2001 From: Mariam05 Date: Thu, 14 Nov 2024 10:17:38 -0500 Subject: [PATCH] LTI-411: reduce database queries to improve performance --- app/controllers/rooms_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 2eb66642..675783c0 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -290,11 +290,15 @@ def set_room def set_chosen_room # See whether shared rooms have been enabled in tenant settings. They are disabled by default. @shared_rooms_enabled = tenant_setting(@room&.tenant, 'enable_shared_rooms') == 'true' - @shared_room = Room.find_by(code: @room.shared_code, tenant: @room.tenant) if @shared_rooms_enabled && @room&.use_shared_code - use_shared_room = @shared_rooms_enabled && @room&.use_shared_code && Room.where(code: @room.shared_code, tenant: @room.tenant).exists? - - logger.debug("Room with id #{params[:id]} is using shared code: #{@room&.shared_code}") if @shared_rooms_enabled && @room&.use_shared_code + if @shared_rooms_enabled && @room&.use_shared_code + @shared_room = Room.find_by(code: @room.shared_code, tenant: @room.tenant) + use_shared_room = @shared_room.present? + logger.debug("Room with id #{params[:id]} is using shared code: #{@room&.shared_code}") + else + @shared_room = nil + use_shared_room = false + end @chosen_room = use_shared_room ? @shared_room : @room end