From 6cefd67dc65845fcbb98e8483f16b8190e72b751 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 11 Jun 2014 16:00:28 +0800 Subject: [PATCH] Fix slow impressionist count --- app/models/page.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index 1b6ef08..f36f608 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -3,14 +3,14 @@ class Page < Item include Impressionist::Impressionable include ParserFrontEnd - is_impressionable :counter_cache => { :column_name => :view_count } + is_impressionable field :content, localize: true field :app_frontend_url # field :theme_id, :type => BSON::ObjectId, :default => nil field :category,type: Array, :default => [] field :tag, type: Array,:default => [] - field :view_count, :type => Integer, :default => 0 + # field :view_count, :type => Integer, :default => 0 field :page_title, localize: true field :frontend_style @@ -65,6 +65,10 @@ class Page < Item end end + def view_count + self.impression_count + end + protected def create_parts @@ -97,15 +101,15 @@ class Page < Item end def delete_empty_frontend_field - if self.frontend_field + if self.frontend_field self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) } - # self.frontend_field.each do | ff | - # if ff[0].blank? || ff[1].blank? + # self.frontend_field.each do | ff | + # if ff[0].blank? || ff[1].blank? # self.frontend_field.delete("") if self.frontend_field # self.frontend_field.delete(ff) - # end - # end - end + # end + # end + end end def generate_html