Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-18 11:45:42 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-18 11:45:42 +0300
commitb6de7ad49eb40a108f0776d727ae37adb6f4559e (patch)
treee2a63415c085d58537ae44c1ecf834af04786246 /app/finders
parent0aec0d53b10078613b66b0d41424ee4264ae6406 (diff)
Fix 500 on trending projects if isntance has 100k+ projects
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/trending_projects_finder.rb17
1 files changed, 4 insertions, 13 deletions
diff --git a/app/finders/trending_projects_finder.rb b/app/finders/trending_projects_finder.rb
index f3f4d461efa..9ea342cb26d 100644
--- a/app/finders/trending_projects_finder.rb
+++ b/app/finders/trending_projects_finder.rb
@@ -2,21 +2,12 @@ class TrendingProjectsFinder
def execute(current_user, start_date = nil)
start_date ||= Date.today - 1.month
+ projects = projects_for(current_user)
+
# Determine trending projects based on comments count
# for period of time - ex. month
- trending_project_ids = Note.
- select("notes.project_id, count(notes.project_id) as pcount").
- where('notes.created_at > ?', start_date).
- group("project_id").
- reorder("pcount DESC").
- map(&:project_id)
-
- sql_order_ids = trending_project_ids.reverse.
- map { |project_id| "id = #{project_id}" }.join(", ")
-
- # Get list of projects that user allowed to see
- projects = projects_for(current_user)
- projects.where(id: trending_project_ids).reorder(sql_order_ids)
+ projects.joins(:notes).where('notes.created_at > ?', start_date).
+ group("projects.id").reorder("count(notes.id) DESC")
end
private