From 1b279971afe4a74edf521c4470a719b4d4e23e21 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 24 Mar 2014 10:36:52 -0300 Subject: [PATCH] relevant_content: refactoring most accessed from article --- plugins/relevant_content/lib/ext/article.rb | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/plugins/relevant_content/lib/ext/article.rb b/plugins/relevant_content/lib/ext/article.rb index 9872866..5cb56e0 100644 --- a/plugins/relevant_content/lib/ext/article.rb +++ b/plugins/relevant_content/lib/ext/article.rb @@ -5,24 +5,13 @@ class Article named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] def self.most_accessed(owner, limit = nil) - if owner.kind_of?(Environment) - result = Article.relevant_content.find( - :all, - :order => 'hits desc', - :limit => limit, - :conditions => ["hits > 0"] - ) - result.paginate({:page => 1, :per_page => limit}) - else - #Owner is a profile - result = Article.relevant_content.find( - :all, - :order => 'hits desc', - :limit => limit, - :conditions => ["profile_id = ? and hits > 0", owner.id] - ) - result.paginate({:page => 1, :per_page => limit}) - end + conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id] + result = Article.relevant_content.find( + :all, + :order => 'hits desc', + :limit => limit, + :conditions => conditions) + result.paginate({:page => 1, :per_page => limit}) end def self.most_commented_relevant_content(owner, limit) @@ -191,4 +180,4 @@ class Article -end \ No newline at end of file +end -- libgit2 0.21.2