diff --git a/app/controllers/concerns/bbb_helper.rb b/app/controllers/concerns/bbb_helper.rb index b2169ee7..d4c7e25b 100644 --- a/app/controllers/concerns/bbb_helper.rb +++ b/app/controllers/concerns/bbb_helper.rb @@ -125,31 +125,40 @@ def meeting_running? # Fetches all recordings for a room. def recordings(page = 1) - res = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled - offset = (page.to_i - 1) * RECORDINGS_PER_PAGE # The offset is an index that starts at 0. - res ||= bbb.get_recordings(meetingID: @chosen_room.handler, offset: offset, limit: RECORDINGS_PER_PAGE) # offset and limit are for pagination purposes + res = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}/page#{page}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled + + if res + logger.debug("Pulled recordings from cache: #{res}") + else + offset = (page.to_i - 1) * RECORDINGS_PER_PAGE # The offset is an index that starts at 0. + logger.debug('Could not find recordings in cache. Pulling them from BBB: ') + res ||= bbb.get_recordings(meetingID: @chosen_room.handler, offset: offset, limit: RECORDINGS_PER_PAGE) # offset and limit are for pagination purposes + end + @num_of_recs = res[:totalElements]&.to_i recordings_formatted(res) end def paginate? - @num_of_recs ? @num_of_recs > RECORDINGS_PER_PAGE : false - end + return true if @num_of_recs && @num_of_recs > RECORDINGS_PER_PAGE - # returns the amount of pages for recordings - def pages_count - @num_of_recs ? (@num_of_recs.to_f / RECORDINGS_PER_PAGE).ceil : 1 + recordings_count > RECORDINGS_PER_PAGE end - # on the last page, we don't want recordings that were in the second-to-last page to show - def recordings_limit(page) - page_int = page.to_i - num_of_recs = recordings_count - recordings_overflow = num_of_recs - page_int * RECORDINGS_PER_PAGE - # if offset is > 0 and there are less recordings than the current page * recordings per page, then we'll need to pass a limit that's less than what's defined in RECORDINGS_PER_PAGE - return recordings_overflow if page_int.positive? && recordings_overflow < RECORDINGS_PER_PAGE + # This method is used if #@num_of_recs is null, which means that totalElements is not present in the BBB response. + # Pull the rest of the recordings to see if we need to paginate. + # Set offset to 8 because we know that at least one page was already pulled. + # Set the limit to the max number of recordings that can be pulled. + def recordings_count + res_count = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}/remaining", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled + res_count ||= bbb.get_recordings(meetingID: @chosen_room.handler, offset: RECORDINGS_PER_PAGE, limit: 100)[:recordings].length + @num_of_recs = res_count + RECORDINGS_PER_PAGE # We add RECORDINGS_PER_PAGE because we set the offset to 1 + @num_of_recs + end - RECORDINGS_PER_PAGE + # returns the amount of pages for recordings + def pages_count + (@num_of_recs.to_f / RECORDINGS_PER_PAGE).ceil end # Fetch an individual recording diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 675783c0..40d8211c 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -236,6 +236,8 @@ def recording_delete def individual_recording rec = recording(params[:record_id]) formats_arr = rec[:playback][:format] + formats_arr = [formats_arr] unless formats_arr.is_a?(Array) # for when BBB returns just one format + format_obj = formats_arr.find { |i| i[:type] == params[:format] } playback_url = format_obj[:url] diff --git a/app/views/shared/_room.html.erb b/app/views/shared/_room.html.erb index 7b6ebd60..e1c733df 100644 --- a/app/views/shared/_room.html.erb +++ b/app/views/shared/_room.html.erb @@ -196,8 +196,8 @@ - <% numOfPages = pages_count %> <% if paginate? %> + <% numOfPages = pages_count %>