Commit dff16e9db50b5a65cd0e71f01e856de09684e089

Authored by Luke Baker
1 parent be9cfad1

add max_ids structure

Showing 1 changed file with 29 additions and 14 deletions   Show diff stats
lib/tasks/timezone.rake
@@ -63,19 +63,34 @@ namespace :timezone do @@ -63,19 +63,34 @@ namespace :timezone do
63 # :h => t[:h] } 63 # :h => t[:h] }
64 #end 64 #end
65 datetime_fields = { 65 datetime_fields = {
66 - #:appearances => ['created_at', 'updated_at'],  
67 - #:choices => ['created_at', 'updated_at'],  
68 - #:clicks => ['created_at', 'updated_at'],  
69 - #:densities => ['created_at', 'updated_at'],  
70 - #:flags => ['created_at', 'updated_at'],  
71 - #:prompts => ['created_at', 'updated_at'], 66 + :appearances => ['created_at', 'updated_at'],
  67 + :choices => ['created_at', 'updated_at'],
  68 + :clicks => ['created_at', 'updated_at'],
  69 + :densities => ['created_at', 'updated_at'],
  70 + :flags => ['created_at', 'updated_at'],
  71 + :prompts => ['created_at', 'updated_at'],
72 :skips => ['created_at', 'updated_at'], 72 :skips => ['created_at', 'updated_at'],
73 - #:votes => ['created_at', 'updated_at'],  
74 - #:visitors => ['created_at', 'updated_at'],  
75 - #:users => ['created_at', 'updated_at'],  
76 - #:questions => ['created_at', 'updated_at'],  
77 - #:question_versions => ['created_at', 'updated_at'],  
78 - #:delayed_jobs => ['created_at', 'updated_at', 'run_at', 'locked_at', 'failed_at'], 73 + :votes => ['created_at', 'updated_at'],
  74 + :visitors => ['created_at', 'updated_at'],
  75 + :users => ['created_at', 'updated_at'],
  76 + :questions => ['created_at', 'updated_at'],
  77 + :question_versions => ['created_at', 'updated_at'],
  78 + :delayed_jobs => ['created_at', 'updated_at', 'run_at', 'locked_at', 'failed_at'],
  79 + }
  80 + max_ids = {
  81 + :appearances => 99999999999999,
  82 + :choices => 99999999999999,
  83 + :clicks => 99999999999999,
  84 + :densities => 99999999999999,
  85 + :flags => 99999999999999,
  86 + :prompts => 99999999999999,
  87 + :skips => 99999999999999,
  88 + :votes => 99999999999999,
  89 + :visitors => 99999999999999,
  90 + :users => 99999999999999,
  91 + :questions => 99999999999999,
  92 + :question_versions => 99999999999999,
  93 + :delayed_jobs => 99999999999999,
79 } 94 }
80 95
81 STDOUT.sync = true 96 STDOUT.sync = true
@@ -84,12 +99,12 @@ namespace :timezone do @@ -84,12 +99,12 @@ namespace :timezone do
84 print "#{table}" 99 print "#{table}"
85 batch_size = 10000 100 batch_size = 10000
86 i = 0 101 i = 0
87 - where = '' 102 + where = "WHERE id < #{max_ids[table]}"
88 # This is how we split the rows of a table between the various workers 103 # This is how we split the rows of a table between the various workers
89 # so that they don't attempt to work on the same row as another worker. 104 # so that they don't attempt to work on the same row as another worker.
90 # The workerid is any number 0 through workers - 1. 105 # The workerid is any number 0 through workers - 1.
91 if args[:workers] > "1" 106 if args[:workers] > "1"
92 - where = "WHERE MOD(id, #{args[:workers]}) = #{args[:workerid]}" 107 + where += " AND MOD(id, #{args[:workers]}) = #{args[:workerid]}"
93 end 108 end
94 while true do 109 while true do
95 rows = ActiveRecord::Base.connection.select_all( 110 rows = ActiveRecord::Base.connection.select_all(