forked from External/greenlight
Cached request to provider to increase application performance (#755)
This commit is contained in:
parent
3d2a0a060b
commit
177bf4d595
|
@ -176,6 +176,14 @@ class AdminsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# POST /admins/clear_cache
|
||||||
|
def clear_cache
|
||||||
|
Rails.cache.delete("#{@user_domain}/getUser")
|
||||||
|
Rails.cache.delete("#{@user_domain}/getUserGreenlightCredentials")
|
||||||
|
|
||||||
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") }
|
||||||
|
end
|
||||||
|
|
||||||
# ROLES
|
# ROLES
|
||||||
|
|
||||||
# GET /admins/roles
|
# GET /admins/roles
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="mb-6 row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label"><%= t("administrator.site_settings.rooms.title") %></label>
|
<label class="form-label"><%= t("administrator.site_settings.rooms.title") %></label>
|
||||||
|
@ -154,4 +154,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% if current_user.has_role? :super_admin%>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="mb-6 form-group">
|
||||||
|
<label class="form-label"><%= t("administrator.site_settings.cache.title") %></label>
|
||||||
|
<label class="form-label text-muted"><%= t("administrator.site_settings.cache.info") %></label>
|
||||||
|
<%= button_to t("administrator.site_settings.cache.button"), admin_clear_cache_path, class: "btn btn-primary" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -42,6 +42,10 @@ en:
|
||||||
info: Change the branding image that appears in the top left corner
|
info: Change the branding image that appears in the top left corner
|
||||||
placeholder: Image Url...
|
placeholder: Image Url...
|
||||||
title: Branding Image
|
title: Branding Image
|
||||||
|
cache:
|
||||||
|
info: Clears the stored provider cache which forces a new request for the updated info
|
||||||
|
title: Clear Provider Cache
|
||||||
|
button: Clear Cache
|
||||||
color:
|
color:
|
||||||
info: Changing the Regular Color will change both Lighten and Darken. Lighten and Darken can then be changed individually
|
info: Changing the Regular Color will change both Lighten and Darken. Lighten and Darken can then be changed individually
|
||||||
title: Primary Color
|
title: Primary Color
|
||||||
|
|
|
@ -54,6 +54,7 @@ Rails.application.routes.draw do
|
||||||
get '/reset', to: 'admins#reset', as: :admin_reset
|
get '/reset', to: 'admins#reset', as: :admin_reset
|
||||||
post '/room_limit', to: 'admins#room_limit', as: :admin_room_limit
|
post '/room_limit', to: 'admins#room_limit', as: :admin_room_limit
|
||||||
post '/default_recording_visibility', to: 'admins#default_recording_visibility', as: :admin_recording_visibility
|
post '/default_recording_visibility', to: 'admins#default_recording_visibility', as: :admin_recording_visibility
|
||||||
|
post '/clear_cache', to: 'admins#clear_cache', as: :admin_clear_cache
|
||||||
get '/roles', to: 'admins#roles', as: :admin_roles
|
get '/roles', to: 'admins#roles', as: :admin_roles
|
||||||
post '/role', to: 'admins#new_role', as: :admin_new_role
|
post '/role', to: 'admins#new_role', as: :admin_new_role
|
||||||
patch 'roles/order', to: 'admins#change_role_order', as: :admin_roles_order
|
patch 'roles/order', to: 'admins#change_role_order', as: :admin_roles_order
|
||||||
|
|
|
@ -27,6 +27,9 @@ module BbbApi
|
||||||
# Include Omniauth accounts under the Greenlight provider.
|
# Include Omniauth accounts under the Greenlight provider.
|
||||||
raise "Provider not included." if !provider || provider.empty?
|
raise "Provider not included." if !provider || provider.empty?
|
||||||
|
|
||||||
|
cached_provider = Rails.cache.fetch("#{provider}/#{route}")
|
||||||
|
return cached_provider unless cached_provider.nil?
|
||||||
|
|
||||||
# Build the URI.
|
# Build the URI.
|
||||||
uri = encode_bbb_url(
|
uri = encode_bbb_url(
|
||||||
Rails.configuration.loadbalancer_endpoint + api + '/',
|
Rails.configuration.loadbalancer_endpoint + api + '/',
|
||||||
|
@ -48,6 +51,10 @@ module BbbApi
|
||||||
raise doc['message'] unless response.is_a?(Net::HTTPSuccess)
|
raise doc['message'] unless response.is_a?(Net::HTTPSuccess)
|
||||||
|
|
||||||
# Return the user credentials if the request succeeded on the loadbalancer.
|
# Return the user credentials if the request succeeded on the loadbalancer.
|
||||||
|
Rails.cache.fetch("#{provider}/#{route}", expires_in: 1.hours) do
|
||||||
|
doc['user']
|
||||||
|
end
|
||||||
|
|
||||||
return doc['user'] if doc['returncode'] == 'SUCCESS'
|
return doc['user'] if doc['returncode'] == 'SUCCESS'
|
||||||
|
|
||||||
raise "User with provider #{provider} does not exist." if doc['messageKey'] == 'noSuchUser'
|
raise "User with provider #{provider} does not exist." if doc['messageKey'] == 'noSuchUser'
|
||||||
|
|
Loading…
Reference in New Issue