mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Explicitly avoid all readonly protection and scoping
This commit is contained in:
parent
7ca8853861
commit
0d816302e2
@ -23,6 +23,10 @@ class ApplicationRequest < ActiveRecord::Base
|
|||||||
def self.increment!(type, opts = nil)
|
def self.increment!(type, opts = nil)
|
||||||
key = redis_key(type)
|
key = redis_key(type)
|
||||||
val = $redis.incr(key).to_i
|
val = $redis.incr(key).to_i
|
||||||
|
|
||||||
|
# readonly mode it is going to be 0, skip
|
||||||
|
return if val == 0
|
||||||
|
|
||||||
# 3.days, see: https://github.com/rails/rails/issues/21296
|
# 3.days, see: https://github.com/rails/rails/issues/21296
|
||||||
$redis.expire(key, 259200)
|
$redis.expire(key, 259200)
|
||||||
|
|
||||||
@ -60,12 +64,15 @@ class ApplicationRequest < ActiveRecord::Base
|
|||||||
key = redis_key(req_type, date)
|
key = redis_key(req_type, date)
|
||||||
|
|
||||||
namespaced_key = $redis.namespace_key(key)
|
namespaced_key = $redis.namespace_key(key)
|
||||||
val = $redis.eval(GET_AND_RESET, keys: [namespaced_key]).to_i
|
val = $redis.without_namespace.eval(GET_AND_RESET, keys: [namespaced_key]).to_i
|
||||||
next if val == 0
|
next if val == 0
|
||||||
|
|
||||||
id = req_id(date, req_type)
|
id = req_id(date, req_type)
|
||||||
where(id: id).update_all(["count = count + ?", val])
|
where(id: id).update_all(["count = count + ?", val])
|
||||||
end
|
end
|
||||||
|
rescue Redis::CommandError => e
|
||||||
|
raise unless e.message =~ /READONLY/
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear_cache!(date = nil)
|
def self.clear_cache!(date = nil)
|
||||||
|
@ -34,6 +34,8 @@ describe ApplicationRequest do
|
|||||||
|
|
||||||
# flush will be deferred no error raised
|
# flush will be deferred no error raised
|
||||||
inc(:http_total, autoflush: 3)
|
inc(:http_total, autoflush: 3)
|
||||||
|
ApplicationRequest.write_cache!
|
||||||
|
|
||||||
$redis.slaveof("no", "one")
|
$redis.slaveof("no", "one")
|
||||||
|
|
||||||
inc(:http_total, autoflush: 3)
|
inc(:http_total, autoflush: 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user