Commit 70917f628d3dd8d9cb257cf7adf204bfbfb1788f
1 parent
3e8e995f
Exists in
master
and in
1 other branch
Increase performance creating merit actions
Showing
1 changed file
with
5 additions
and
2 deletions
Show diff stats
script/process_merit_rules.rb
@@ -35,13 +35,16 @@ end | @@ -35,13 +35,16 @@ end | ||
35 | # person.sash.destroy unless person.sash.nil? | 35 | # person.sash.destroy unless person.sash.nil? |
36 | #end | 36 | #end |
37 | 37 | ||
38 | +# avoid updating level on every action for increasing performance | ||
39 | +Merit.observers.delete('RankObserver') | ||
40 | + | ||
38 | Merit.observers << 'ProcessObserver' | 41 | Merit.observers << 'ProcessObserver' |
39 | 42 | ||
40 | class Article < ActiveRecord::Base | 43 | class Article < ActiveRecord::Base |
41 | def self.text_article_types | 44 | def self.text_article_types |
42 | # ['TextArticle', 'TextileArticle', 'TinyMceArticle', 'ProposalsDiscussionPlugin::Proposal'] | 45 | # ['TextArticle', 'TextileArticle', 'TinyMceArticle', 'ProposalsDiscussionPlugin::Proposal'] |
43 | ['ProposalsDiscussionPlugin::Proposal'] | 46 | ['ProposalsDiscussionPlugin::Proposal'] |
44 | - end | 47 | + end |
45 | end | 48 | end |
46 | 49 | ||
47 | Environment.all.each do |environment| | 50 | Environment.all.each do |environment| |
@@ -56,7 +59,7 @@ Environment.all.each do |environment| | @@ -56,7 +59,7 @@ Environment.all.each do |environment| | ||
56 | article_index = 0 | 59 | article_index = 0 |
57 | 60 | ||
58 | puts "Amount of articles '#{article_count}'" | 61 | puts "Amount of articles '#{article_count}'" |
59 | - environment.articles.where(:type => Article.text_article_types).find_each do |article| | 62 | + environment.articles.includes(:comments).where(:type => Article.text_article_types).find_each(batch_size: 100) do |article| |
60 | article_index += 1 | 63 | article_index += 1 |
61 | puts "Analising article #{article_index} of #{article_count}" | 64 | puts "Analising article #{article_index} of #{article_count}" |
62 | create_action(article, article_index, article_count) | 65 | create_action(article, article_index, article_count) |