Permalink
Browse files

Try to speed up the initial migration of data

  • Loading branch information...
1 parent 71235f1 commit 092732f72f40ebd91be7709cf01e57b6713c621d @evanphx evanphx committed Sep 16, 2012
Showing with 22 additions and 3 deletions.
  1. +21 −2 app/models/download.rb
  2. +1 −1 lib/tasks/gemcutter.rake
View
23 app/models/download.rb
@@ -117,7 +117,26 @@ def self.copy_to_sql(version, date)
end
end
- def self.migrate_to_sql(version)
+ def self.copy_all_to_sql
+ i = 0
+ count = 0
+ versions = Version.all
+ total = versions.size
+
+ VersionHistory.transaction do
+ versions.each do |ver|
+ i += 1
+ yield total, i, ver if block_given?
+
+ dates = migrate_to_sql ver, false
+ count += 1 unless dates.empty?
+ end
+ end
+
+ count
+ end
+
+ def self.migrate_to_sql(version, remove=true)
key = history_key version
dates = $redis.hkeys(key)
@@ -128,7 +147,7 @@ def self.migrate_to_sql(version)
dates.each do |d|
copy_to_sql version, d
- $redis.hdel key, d
+ $redis.hdel key, d if remove
end
dates
View
2 lib/tasks/gemcutter.rake
@@ -61,7 +61,7 @@ namespace :gemcutter do
desc "Move all but the last 2 days of version history to SQL"
task :migrate_history => :environment do
- Download.migrate_all_to_sql do |t,c,v|
+ Download.copy_all_to_sql do |t,c,v|
puts "#{c} of #{t}: #{v.full_name}"
end
end

0 comments on commit 092732f

Please sign in to comment.