BigW Consortium Gitlab

trending_projects_finder.rb 535 Bytes
Newer Older
Dmitriy Zaporozhets committed
1 2 3 4 5 6 7 8 9 10
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).
      select("projects.*, count(notes.id) as ncount").
11
      group("projects.id").reorder("ncount DESC")
Dmitriy Zaporozhets committed
12 13 14 15 16 17 18 19
  end

  private

  def projects_for(current_user)
    ProjectsFinder.new.execute(current_user)
  end
end