Commit 70917f628d3dd8d9cb257cf7adf204bfbfb1788f

Authored by Hugo Melo
1 parent 3e8e995f

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 35 # person.sash.destroy unless person.sash.nil?
36 36 #end
37 37  
  38 +# avoid updating level on every action for increasing performance
  39 +Merit.observers.delete('RankObserver')
  40 +
38 41 Merit.observers << 'ProcessObserver'
39 42  
40 43 class Article < ActiveRecord::Base
41 44 def self.text_article_types
42 45 # ['TextArticle', 'TextileArticle', 'TinyMceArticle', 'ProposalsDiscussionPlugin::Proposal']
43 46 ['ProposalsDiscussionPlugin::Proposal']
44   - end
  47 + end
45 48 end
46 49  
47 50 Environment.all.each do |environment|
... ... @@ -56,7 +59,7 @@ Environment.all.each do |environment|
56 59 article_index = 0
57 60  
58 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 63 article_index += 1
61 64 puts "Analising article #{article_index} of #{article_count}"
62 65 create_action(article, article_index, article_count)
... ...