45cf64c827
Makes it easier and safer to use RequestStore because you don't need to check `RequestStore.active?` before using it. You just have to use `Gitlab::SafeRequestStore` instead.
23 lines
574 B
Ruby
23 lines
574 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module SafeRequestStore
|
|
NULL_STORE = Gitlab::NullRequestStore.new
|
|
|
|
class << self
|
|
# These methods should always run directly against RequestStore
|
|
delegate :clear!, :begin!, :end!, :active?, to: :RequestStore
|
|
|
|
# These methods will run against NullRequestStore if RequestStore is disabled
|
|
delegate :read, :[], :write, :[]=, :exist?, :fetch, :delete, to: :store
|
|
end
|
|
|
|
def self.store
|
|
if RequestStore.active?
|
|
RequestStore
|
|
else
|
|
NULL_STORE
|
|
end
|
|
end
|
|
end
|
|
end
|