mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Add rubocop to our build. (#5004)
This commit is contained in:
@ -19,7 +19,7 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
self.autoflush_seconds = 5.minutes
|
||||
self.last_flush = Time.now.utc
|
||||
|
||||
def self.increment!(type, opts=nil)
|
||||
def self.increment!(type, opts = nil)
|
||||
key = redis_key(type)
|
||||
val = $redis.incr(key).to_i
|
||||
# 3.days, see: https://github.com/rails/rails/issues/21296
|
||||
@ -36,7 +36,7 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.write_cache!(date=nil)
|
||||
def self.write_cache!(date = nil)
|
||||
if date.nil?
|
||||
write_cache!(Time.now.utc)
|
||||
write_cache!(Time.now.utc.yesterday)
|
||||
@ -49,8 +49,8 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
|
||||
# this may seem a bit fancy but in so it allows
|
||||
# for concurrent calls without double counting
|
||||
req_types.each do |req_type,_|
|
||||
key = redis_key(req_type,date)
|
||||
req_types.each do |req_type, _|
|
||||
key = redis_key(req_type, date)
|
||||
val = $redis.get(key).to_i
|
||||
|
||||
next if val == 0
|
||||
@ -63,28 +63,28 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
next
|
||||
end
|
||||
|
||||
id = req_id(date,req_type)
|
||||
id = req_id(date, req_type)
|
||||
|
||||
where(id: id).update_all(["count = count + ?", val])
|
||||
end
|
||||
end
|
||||
|
||||
def self.clear_cache!(date=nil)
|
||||
def self.clear_cache!(date = nil)
|
||||
if date.nil?
|
||||
clear_cache!(Time.now.utc)
|
||||
clear_cache!(Time.now.utc.yesterday)
|
||||
return
|
||||
end
|
||||
|
||||
req_types.each do |req_type,_|
|
||||
key = redis_key(req_type,date)
|
||||
req_types.each do |req_type, _|
|
||||
key = redis_key(req_type, date)
|
||||
$redis.del key
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.req_id(date,req_type,retries=0)
|
||||
def self.req_id(date, req_type, retries = 0)
|
||||
|
||||
req_type_id = req_types[req_type]
|
||||
|
||||
@ -94,13 +94,13 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
|
||||
rescue # primary key violation
|
||||
if retries == 0
|
||||
req_id(date,req_type,1)
|
||||
req_id(date, req_type, 1)
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
def self.redis_key(req_type, time=Time.now.utc)
|
||||
def self.redis_key(req_type, time = Time.now.utc)
|
||||
"app_req_#{req_type}#{time.strftime('%Y%m%d')}"
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user