Memorize config options instead of reading them from file over and over again

This commit is contained in:
Sebastian Serth
2022-09-23 11:39:08 +02:00
parent c2c8cf4ae6
commit 5881795d5f
5 changed files with 11 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
include Pundit::Authorization
MEMBER_ACTIONS = %i[destroy edit show update].freeze
RENDER_HOST = CodeOcean::Config.new(:code_ocean).read[:render_host]
after_action :verify_authorized, except: %i[welcome]
around_action :mnemosyne_trace

View File

@@ -3,6 +3,8 @@
module ExerciseHelper
include LtiHelper
CODEPILOT_CONFIG = CodeOcean::Config.new(:code_ocean).read[:code_pilot]
def embedding_parameters(exercise)
"locale=#{I18n.locale}&token=#{exercise.token}"
end
@@ -12,11 +14,6 @@ module ExerciseHelper
end
def qa_url
config = CodeOcean::Config.new(:code_ocean)
enabled = config.read[:code_pilot][:enabled]
if enabled
config.read[:code_pilot][:url]
end
CODEPILOT_CONFIG[:url] if CODEPILOT_CONFIG[:enabled]
end
end

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
class CodeharborLinkPolicy < ApplicationPolicy
CODEHARBOR_CONFIG = CodeOcean::Config.new(:code_ocean).read[:codeharbor]
def index?
false
end
@@ -30,7 +32,7 @@ class CodeharborLinkPolicy < ApplicationPolicy
end
def enabled?
CodeOcean::Config.new(:code_ocean).read[:codeharbor][:enabled]
CODEHARBOR_CONFIG[:enabled]
end
private