Skip to content

Fixes #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions app/models/application_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,6 @@ def self.increment!(type, opts=nil)
end

def self.write_cache!(date=nil)
if date.nil?
write_cache!(Time.now.utc)
write_cache!(Time.now.utc.yesterday)
return
end

self.last_flush = Time.now.utc

date = date.to_date

# 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)
val = $redis.get(key).to_i

next if val == 0

new_val = $redis.incrby(key, -val).to_i

if new_val < 0
# undo and flush next time
$redis.incrby(key, val)
next
end

id = req_id(date,req_type)

where(id: id).update_all(["count = count + ?", val])
end
end

def self.clear_cache!(date=nil)
Expand All @@ -82,8 +52,6 @@ def self.clear_cache!(date=nil)
end
end

protected

def self.req_id(date,req_type,retries=0)

req_type_id = req_types[req_type]
Expand Down