Commit 31bf0cd8763b01ec028f8cd5eeaee43c745ad7c6

Authored by Alexey Loktionov
1 parent b339c747

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

app/controllers/dashboard_controller.rb
... ... @@ -5,7 +5,7 @@ class DashboardController < ApplicationController
5 5  
6 6 def index
7 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 9 @projects = @projects.page(params[:page]).per(30)
10 10  
11 11 @events = Event.in_projects(current_user.project_ids)
... ...
app/controllers/groups_controller.rb
... ... @@ -54,7 +54,7 @@ class GroupsController < ApplicationController
54 54 end
55 55  
56 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 58 end
59 59  
60 60 def project_ids
... ...
app/roles/account.rb
... ... @@ -67,7 +67,7 @@ module Account
67 67 events = events.recent.limit(1).first
68 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 72 end
73 73 end
... ...