Commit 31bf0cd8 authored by Alexey Loktionov's avatar Alexey Loktionov

fix projects sorting; fix Postgresql issue with LIMIT and DISTINCT; fix query performance

parent b339c747
...@@ -5,7 +5,7 @@ class DashboardController < ApplicationController ...@@ -5,7 +5,7 @@ class DashboardController < ApplicationController
def index def index
@groups = Group.where(id: current_user.projects.pluck(:group_id)) @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) @projects = @projects.page(params[:page]).per(30)
@events = Event.in_projects(current_user.project_ids) @events = Event.in_projects(current_user.project_ids)
......
...@@ -54,7 +54,7 @@ class GroupsController < ApplicationController ...@@ -54,7 +54,7 @@ class GroupsController < ApplicationController
end end
def projects 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 end
def project_ids def project_ids
......
...@@ -67,7 +67,7 @@ module Account ...@@ -67,7 +67,7 @@ module Account
events = events.recent.limit(1).first events = events.recent.limit(1).first
end end
def projects_with_events def projects_sorted_by_activity
projects.includes(:events).order("events.created_at DESC") projects.order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC")
end end
end end
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