Commit dff16e9db50b5a65cd0e71f01e856de09684e089
1 parent
be9cfad1
Exists in
master
and in
1 other branch
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 | 63 | # :h => t[:h] } |
64 | 64 | #end |
65 | 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 | 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 | 96 | STDOUT.sync = true |
... | ... | @@ -84,12 +99,12 @@ namespace :timezone do |
84 | 99 | print "#{table}" |
85 | 100 | batch_size = 10000 |
86 | 101 | i = 0 |
87 | - where = '' | |
102 | + where = "WHERE id < #{max_ids[table]}" | |
88 | 103 | # This is how we split the rows of a table between the various workers |
89 | 104 | # so that they don't attempt to work on the same row as another worker. |
90 | 105 | # The workerid is any number 0 through workers - 1. |
91 | 106 | if args[:workers] > "1" |
92 | - where = "WHERE MOD(id, #{args[:workers]}) = #{args[:workerid]}" | |
107 | + where += " AND MOD(id, #{args[:workers]}) = #{args[:workerid]}" | |
93 | 108 | end |
94 | 109 | while true do |
95 | 110 | rows = ActiveRecord::Base.connection.select_all( | ... | ... |