Skip to content

Commit

Permalink
LTI-151: refactoring for disabling cache, also fixes issues with sett…
Browse files Browse the repository at this point in the history
…ings (#136)
  • Loading branch information
jfederico authored Aug 17, 2022
1 parent 77d3c75 commit f526c97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
49 changes: 25 additions & 24 deletions app/controllers/concerns/bbb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,9 @@ def meeting_running?

# Fetches all recordings for a room.
def recordings
Rails.cache.fetch("#{@room.handler}/#{RECORDINGS_KEY}", expires_in: 30.minutes) do
res = bbb.get_recordings(meetingID: @room.handler)

# Format playbacks in a more pleasant way.
res[:recordings].each do |r|
next if r.key?(:error)

r[:playbacks] = if !r[:playback] || !r[:playback][:format]
[]
elsif r[:playback][:format].is_a?(Array)
r[:playback][:format]
else
[r[:playback][:format]]
end

r.delete(:playback)
end

res[:recordings].sort_by { |rec| rec[:endTime] }.reverse
end
res = Rails.cache.fetch("#{@room.handler}/#{RECORDINGS_KEY}", expires_in: 30.minutes) if Rails.configuration.cache_enabled
res ||= bbb.get_recordings(meetingID: @room.handler)
recordings_formatted(res)
end

def server_running?
Expand All @@ -137,25 +120,25 @@ def server_running?

# Deletes a recording.
def delete_recording(record_id)
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}")
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled
bbb.delete_recordings(record_id)
end

# Publishes a recording.
def publish_recording(record_id)
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}")
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled
bbb.publish_recordings(record_id, true)
end

# Unpublishes a recording.
def unpublish_recording(record_id)
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}")
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled
bbb.publish_recordings(record_id, false)
end

# Updates a recording.
def update_recording(record_id, meta)
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}")
Rails.cache.delete("#{@room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled
meta[:recordID] = record_id
bbb.send_api_request('updateRecordings', meta)
end
Expand Down Expand Up @@ -234,4 +217,22 @@ def initialize_bbb_credentials
def remove_slash(str)
str.nil? ? nil : str.chomp('/')
end

# Format playbacks in a more pleasant way.
def recordings_formatted(res)
res[:recordings].each do |r|
next if r.key?(:error)

r[:playbacks] = if !r[:playback] || !r[:playback][:format]
[]
elsif r[:playback][:format].is_a?(Array)
r[:playback][:format]
else
[r[:playback][:format]]
end

r.delete(:playback)
end
res[:recordings].sort_by { |rec| rec[:endTime] }.reverse
end
end
6 changes: 3 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ class Application < Rails::Application
config.omniauth_key = ENV['OMNIAUTH_BBBLTIBROKER_KEY']
config.omniauth_secret = ENV['OMNIAUTH_BBBLTIBROKER_SECRET']

config.bigbluebutton_recording_enabled = ENV['BIGBLUEBUTTON_RECORDING_ENABLED'] || true
config.bigbluebutton_recording_enabled = ENV.fetch('BIGBLUEBUTTON_RECORDING_ENABLED', 'true').casecmp?('true')

# Mount Action Cable outside main process or domain
config.action_cable.url = "wss://#{config.relative_url_root}/cable"

# Settings for external services.
config.cache_enabled = ENV['CACHE_ENABLED'] || true
config.cache_enabled = ENV.fetch('CACHE_ENABLED', 'false').casecmp?('true')
config.external_multitenant_endpoint = ENV['EXTERNAL_MULTITENANT_ENDPOINT']
config.external_multitenant_secret = ENV['EXTERNAL_MULTITENANT_SECRET']

config.developer_mode_enabled = (ENV['DEVELOPER_MODE_ENABLED'] == 'true')
config.developer_mode_enabled = ENV.fetch('DEVELOPER_MODE_ENABLED', 'false').casecmp?('true')

config.generators.javascript_engine = :js

Expand Down
2 changes: 1 addition & 1 deletion dotenv
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RAILS_SERVE_STATIC_FILES=true
# RAILS_ENV=development

## Use cache for optimizing requests to external servers (Optional)
# RAILS_CACHE_ENABLED=true
# CACHE_ENABLED=false

## Use to retrieve credentials for a BigBlueButton server per tenant (Optional)
# EXTERNAL_MULTITENANT_ENDPOINT=
Expand Down

0 comments on commit f526c97

Please sign in to comment.