summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Loktionov <la@dalee.ru>2012-11-16 22:31:17 +0400
committerAlexey Loktionov <la@dalee.ru>2012-11-16 22:31:17 +0400
commit31bf0cd8763b01ec028f8cd5eeaee43c745ad7c6 (patch)
tree6e58e072142e781dacb76c6d5d7d98c090ff3e80
parentb339c747a9943e9961239a234dcd6e16566a53e1 (diff)
downloadgitlab-ce-31bf0cd8763b01ec028f8cd5eeaee43c745ad7c6.tar.gz
fix projects sorting; fix Postgresql issue with LIMIT and DISTINCT; fix query performance
-rw-r--r--app/controllers/dashboard_controller.rb2
-rw-r--r--app/controllers/groups_controller.rb2
-rw-r--r--app/roles/account.rb4
3 files changed, 4 insertions, 4 deletions
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 012d86764ab..8d9329f2b32 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 761238a98b5..63f70cd0027 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 21545b91ce1..b80fbba0958 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