@@ -11,11 +11,11 @@ namespace :db do
11
11
'cache:score:recalculate' ]
12
12
13
13
task :fix_counters => :environment do
14
- Comment . find_each do |comment |
14
+ Comment . where ( port_data_since ) . find_each do |comment |
15
15
puts comment . id
16
16
Comment . reset_counters ( comment . id , :likes )
17
17
end
18
- Protip . find_each do |protip |
18
+ Protip . where ( port_data_since ) . find_each do |protip |
19
19
puts protip . id
20
20
Protip . reset_counters ( protip . id , :likes )
21
21
end
@@ -165,13 +165,15 @@ namespace :db do
165
165
end
166
166
167
167
def port_data_since
168
- # OR updated_at > ?
169
- [ "created_at > ?" , 7 . days . ago ]
168
+ days = ENV [ 'since' ] . to_i
169
+ days = 7 if days == 0
170
+ since = days . days . ago
171
+ puts "Porting #{ days } days ago"
172
+ [ "created_at > ?" , since ]
170
173
end
171
174
172
175
task :users => :connect do
173
176
User . reset_pk_sequence
174
- # puts Legacy[:users].where("created_at >= ?", 2.days.ago).count
175
177
Legacy [ :users ] . where ( port_data_since ) . each do |row |
176
178
puts row [ :username ]
177
179
begin
@@ -220,7 +222,7 @@ namespace :db do
220
222
protip . attributes . keys . each do |key |
221
223
protip [ key ] = row [ key . to_sym ]
222
224
end
223
-
225
+ protip . public_id = row [ :public_id ]
224
226
protip . likes_count = ( Legacy [ :likes ] . where ( likable_id : row [ :id ] , likable_type : 'Protip' ) . count + 1 )
225
227
protip . tags = Legacy [ :tags ] . select ( :name ) . join ( :taggings , :tag_id => :id ) . where (
226
228
taggable_id : row [ :id ] ,
0 commit comments