File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,31 @@ namespace :news do
8
8
9
9
# entries を計算
10
10
entries = raw [ 'news' ] || [ ]
11
+ new_count = 0
12
+ updated_count = 0
11
13
12
14
entries . each do |attrs |
13
15
news = News . find_or_initialize_by ( url : attrs [ 'url' ] )
16
+ is_new = news . new_record?
17
+
14
18
news . assign_attributes (
15
19
title : attrs [ 'title' ] ,
16
20
published_at : attrs [ 'published_at' ]
17
21
)
18
- news . save!
19
- puts "[news] #{ news . published_at . to_date } #{ news . title } "
22
+
23
+ if is_new || news . changed?
24
+ news . save!
25
+ if is_new
26
+ new_count += 1
27
+ status = 'new'
28
+ else
29
+ updated_count += 1
30
+ status = 'updated'
31
+ end
32
+ puts "[News] #{ news . published_at . to_date } #{ news . title } (#{ status } )"
33
+ end
20
34
end
21
35
22
- puts "Imported #{ entries . size } items."
36
+ puts "Imported #{ new_count + updated_count } items ( #{ new_count } new, #{ updated_count } updated) ."
23
37
end
24
38
end
You can’t perform that action at this time.
0 commit comments