From 9480ac712e653ed16b65db10ff3dbd5b4f794eec Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 12 Dec 2012 19:44:50 +0000 Subject: [PATCH] [pluginize-solr] Moving solr_save calls on add_category methods --- app/models/article.rb | 19 ------------------- app/models/profile.rb | 1 - plugins/solr/lib/ext/article.rb | 29 +++++++++++++++++++++++++++++ plugins/solr/lib/ext/profile.rb | 8 ++++++++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 0c6c2bd..1ce2dc2 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -142,7 +142,6 @@ class Article < ActiveRecord::Base else ArticleCategorization.add_category_to_article(c, self) self.categories(reload) - self.solr_save end end @@ -160,7 +159,6 @@ class Article < ActiveRecord::Base ArticleCategorization.add_category_to_article(item, self) end self.categories(true) - self.solr_save pending_categorizations.clear end @@ -630,23 +628,6 @@ class Article < ActiveRecord::Base img.nil? ? '' : img.attributes['src'] end - private - - # FIXME: workaround for development env. - # Subclasses aren't (re)loaded, and acts_as_solr - # depends on subclasses method to search - # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245 - UploadedFile - TextArticle - TinyMceArticle - TextileArticle - Folder - EnterpriseHomepage - Gallery - Blog - Forum - Event - delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true private diff --git a/app/models/profile.rb b/app/models/profile.rb index b1266f3..f14d666 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -246,7 +246,6 @@ class Profile < ActiveRecord::Base else ProfileCategorization.add_category_to_profile(c, self) self.categories(true) - self.solr_save end self.categories(reload) end diff --git a/plugins/solr/lib/ext/article.rb b/plugins/solr/lib/ext/article.rb index c115a39..795d859 100644 --- a/plugins/solr/lib/ext/article.rb +++ b/plugins/solr/lib/ext/article.rb @@ -38,6 +38,20 @@ class Article solr_save end + def add_category_with_solr_save(c, reload=false) + add_category_without_solr_save(c, reload) + if !new_record? + self.solr_save + end + end + alias_method_chain :add_category, :solr_save + + def create_pending_categorizations_with_solr_save + create_pending_categorizations_without_solr_save + self.solr_save + end + alias_method_chain :create_pending_categorizations, :solr_save + private def self.solr_plugin_f_type_proc(klass) @@ -81,4 +95,19 @@ class Article def solr_plugin_name_sortable name end + + # FIXME: workaround for development env. + # Subclasses aren't (re)loaded, and acts_as_solr + # depends on subclasses method to search + # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245 + UploadedFile + TextArticle + TinyMceArticle + TextileArticle + Folder + EnterpriseHomepage + Gallery + Blog + Forum + Event end diff --git a/plugins/solr/lib/ext/profile.rb b/plugins/solr/lib/ext/profile.rb index 8ce25f6..060f3ab 100644 --- a/plugins/solr/lib/ext/profile.rb +++ b/plugins/solr/lib/ext/profile.rb @@ -44,6 +44,14 @@ class Profile self.solr_plugin_extra_index_methods.push(block) if block_given? end + def add_category_with_solr_save(c, reload=false) + add_category_without_solr_save(c, reload) + if !new_record? + self.solr_save + end + end + alias_method_chain :add_category, :solr_save + private def self.solr_plugin_f_categories_label_proc(environment) -- libgit2 0.21.2