Skip to content

Commit

Permalink
remove 'already initialized constant' warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Jan 11, 2017
1 parent d6bf5b0 commit dfb633f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/discourse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def self.base_url
base_url_no_prefix + base_uri
end

READONLY_MODE_KEY_TTL ||= 60
READONLY_MODE_KEY ||= 'readonly_mode'.freeze
PG_READONLY_MODE_KEY ||= 'readonly_mode:postgres'.freeze
READONLY_MODE_KEY_TTL ||= 60
READONLY_MODE_KEY ||= 'readonly_mode'.freeze
PG_READONLY_MODE_KEY ||= 'readonly_mode:postgres'.freeze
USER_READONLY_MODE_KEY ||= 'readonly_mode:user'.freeze

READONLY_KEYS = [
READONLY_KEYS ||= [
READONLY_MODE_KEY,
PG_READONLY_MODE_KEY,
USER_READONLY_MODE_KEY
Expand Down Expand Up @@ -234,18 +234,15 @@ def self.disable_readonly_mode(key = READONLY_MODE_KEY)
end

def self.readonly_mode?
return true if recently_readonly?
READONLY_KEYS.each { |key| return true if !!$redis.get(key) }
false
recently_readonly? || READONLY_KEYS.any? { |key| !!$redis.get(key) }
end

def self.last_read_only
@last_read_only ||= {}
end

def self.recently_readonly?
read_only = last_read_only[$redis.namespace]
return false unless read_only
return false unless read_only = last_read_only[$redis.namespace]
read_only > 15.seconds.ago
end

Expand Down

0 comments on commit dfb633f

Please sign in to comment.