gitlab-org--gitlab-foss/app/finders/trending_projects_finder.rb
Dmitriy Zaporozhets b6de7ad49e
Fix 500 on trending projects if isntance has 100k+ projects
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2015-09-18 10:45:42 +02:00

18 lines
489 B
Ruby

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
projects.joins(:notes).where('notes.created_at > ?', start_date).
group("projects.id").reorder("count(notes.id) DESC")
end
private
def projects_for(current_user)
ProjectsFinder.new.execute(current_user)
end
end