diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 012d86764ab9fd0eefb89ff7452b6a2e4f17bb5c..8d9329f2b32e0f5d03c31fbe59da544c69d6e105 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -5,7 +5,7 @@ class DashboardController < ApplicationController def index @groups = Group.where(id: current_user.projects.pluck(:group_id)) - @projects = current_user.projects_with_events + @projects = current_user.projects_sorted_by_activity @projects = @projects.page(params[:page]).per(30) @events = Event.in_projects(current_user.project_ids) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 761238a98b5f602d74ae6adfab4f706b2a28ab3f..63f70cd00275dc9b57f072ade08b2055378cc545 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -54,7 +54,7 @@ class GroupsController < ApplicationController end def projects - @projects ||= current_user.projects_with_events.where(group_id: @group.id) + @projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id) end def project_ids diff --git a/app/roles/account.rb b/app/roles/account.rb index 21545b91ce1a30d1cdbfc3c6b56a286417dd39c7..b80fbba0958d3f64b054fe0924eaa9c16bf8ae7c 100644 --- a/app/roles/account.rb +++ b/app/roles/account.rb @@ -67,7 +67,7 @@ module Account events = events.recent.limit(1).first end - def projects_with_events - projects.includes(:events).order("events.created_at DESC") + def projects_sorted_by_activity + projects.order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") end end