Commit b6de7ad4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix 500 on trending projects if isntance has 100k+ projects

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0aec0d53
...@@ -2,21 +2,12 @@ class TrendingProjectsFinder ...@@ -2,21 +2,12 @@ class TrendingProjectsFinder
def execute(current_user, start_date = nil) def execute(current_user, start_date = nil)
start_date ||= Date.today - 1.month start_date ||= Date.today - 1.month
projects = projects_for(current_user)
# Determine trending projects based on comments count # Determine trending projects based on comments count
# for period of time - ex. month # for period of time - ex. month
trending_project_ids = Note. projects.joins(:notes).where('notes.created_at > ?', start_date).
select("notes.project_id, count(notes.project_id) as pcount"). group("projects.id").reorder("count(notes.id) DESC")
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)
end end
private private
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
= render "shared/projects/project", project: project, = render "shared/projects/project", project: project,
avatar: avatar, stars: stars, css_class: css_class avatar: avatar, stars: stars, css_class: css_class
- if projects.count > projects_limit - if projects.size > projects_limit
%li.bottom.center %li.bottom.center
.light .light
#{projects_limit} of #{pluralize(projects.count, 'project')} displayed. #{projects_limit} of #{pluralize(projects.count, 'project')} displayed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment