Commit 31bf0cd8763b01ec028f8cd5eeaee43c745ad7c6
1 parent
b339c747
Exists in
master
and in
4 other branches
fix projects sorting; fix Postgresql issue with LIMIT and DISTINCT; fix query performance
Showing
3 changed files
with
4 additions
and
4 deletions
Show diff stats
app/controllers/dashboard_controller.rb
| @@ -5,7 +5,7 @@ class DashboardController < ApplicationController | @@ -5,7 +5,7 @@ class DashboardController < ApplicationController | ||
| 5 | 5 | ||
| 6 | def index | 6 | def index |
| 7 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) | 7 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) |
| 8 | - @projects = current_user.projects_with_events | 8 | + @projects = current_user.projects_sorted_by_activity |
| 9 | @projects = @projects.page(params[:page]).per(30) | 9 | @projects = @projects.page(params[:page]).per(30) |
| 10 | 10 | ||
| 11 | @events = Event.in_projects(current_user.project_ids) | 11 | @events = Event.in_projects(current_user.project_ids) |
app/controllers/groups_controller.rb
| @@ -54,7 +54,7 @@ class GroupsController < ApplicationController | @@ -54,7 +54,7 @@ class GroupsController < ApplicationController | ||
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | def projects | 56 | def projects |
| 57 | - @projects ||= current_user.projects_with_events.where(group_id: @group.id) | 57 | + @projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id) |
| 58 | end | 58 | end |
| 59 | 59 | ||
| 60 | def project_ids | 60 | def project_ids |
app/roles/account.rb
| @@ -67,7 +67,7 @@ module Account | @@ -67,7 +67,7 @@ module Account | ||
| 67 | events = events.recent.limit(1).first | 67 | events = events.recent.limit(1).first |
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | - def projects_with_events | ||
| 71 | - projects.includes(:events).order("events.created_at DESC") | 70 | + def projects_sorted_by_activity |
| 71 | + projects.order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") | ||
| 72 | end | 72 | end |
| 73 | end | 73 | end |