Permalink
Browse files

don't drop downloads into a hash, just group by 2 and roll with it

  • Loading branch information...
1 parent 0c7dde0 commit 68067dc0d0b4c036e830194a43f475245bb5cd98 @qrush qrush committed Dec 7, 2011
Showing with 6 additions and 6 deletions.
  1. +6 −6 app/models/download.rb
View
12 app/models/download.rb
@@ -106,14 +106,14 @@ def self.rollover
$redis.rename TODAY_KEY, YESTERDAY_KEY
yesterday = 1.day.ago.to_date.to_s
- versions = Version.includes(:rubygem).inject({}) do |hash, v|
- hash[v.full_name] = v
- hash
+ versions = {}
+
+ Version.find_each(include: :rubygem, batch_size: 10000) do |version|
+ versions[version.full_name] = version
end
- downloads = Hash[*$redis.zrange(YESTERDAY_KEY, 0, -1, :with_scores => true)]
- downloads.each do |key, score|
- if version = versions[key]
+ $redis.zrange(YESTERDAY_KEY, 0, -1, with_scores: true).in_groups_of(2).each do |(full_name, score)|
+ if version = versions[full_name]
$redis.hincrby history_key(version), yesterday, score.to_i
$redis.hincrby history_key(version.rubygem), yesterday, score.to_i
version.rubygem.increment! :downloads, score.to_i

0 comments on commit 68067dc

Please sign in to comment.