summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-18 09:38:46 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-18 09:38:46 -0800
commit63f11a68c5e9edf36d062bd4f029d81a0861ef82 (patch)
tree45edeacc3b0e8f102bc43bbc5e693f52b64ce1f9
parenta6070074bc30cf2e6c9eb9b053fc79bdd35d9d6b (diff)
downloadgitlab-ce-63f11a68c5e9edf36d062bd4f029d81a0861ef82.tar.gz
Fix event loading with associations
-rw-r--r--app/controllers/dashboard_controller.rb15
-rw-r--r--app/controllers/groups_controller.rb15
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/controllers/users_controller.rb2
-rw-r--r--app/models/event.rb1
5 files changed, 25 insertions, 10 deletions
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index ee9dc343337..eca7b39bcdf 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -22,13 +22,14 @@ class DashboardController < ApplicationController
format.html
format.json do
- @events = Event.in_projects(current_user.authorized_projects.pluck(:id))
- @events = @event_filter.apply_filter(@events).includes(:target, project: :namespace)
- @events = @events.limit(20).offset(params[:offset] || 0)
+ load_events
pager_json("events/_events", @events.count)
end
- format.atom { render layout: false }
+ format.atom do
+ load_events
+ render layout: false
+ end
end
end
@@ -77,4 +78,10 @@ class DashboardController < ApplicationController
def load_projects
@projects = current_user.authorized_projects.sorted_by_activity.non_archived
end
+
+ def load_events
+ @events = Event.in_projects(current_user.authorized_projects.pluck(:id))
+ @events = @event_filter.apply_filter(@events).with_associations
+ @events = @events.limit(20).offset(params[:offset] || 0)
+ end
end
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 7b7531f1426..d011523c94f 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -39,13 +39,14 @@ class GroupsController < ApplicationController
format.html
format.json do
- @events = Event.in_projects(project_ids)
- @events = event_filter.apply_filter(@events).includes(:target, project: :namespace)
- @events = @events.limit(20).offset(params[:offset] || 0)
+ load_events
pager_json("events/_events", @events.count)
end
- format.atom { render layout: false }
+ format.atom do
+ load_events
+ render layout: false
+ end
end
end
@@ -154,4 +155,10 @@ class GroupsController < ApplicationController
def group_params
params.require(:group).permit(:name, :description, :path, :avatar)
end
+
+ def load_events
+ @events = Event.in_projects(project_ids)
+ @events = event_filter.apply_filter(@events).with_associations
+ @events = @events.limit(20).offset(params[:offset] || 0)
+ end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index fb58ddd06e7..b0fde88babc 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -76,7 +76,7 @@ class ProjectsController < ApplicationController
format.json do
@events = @project.events.recent
- @events = event_filter.apply_filter(@events).includes(:target, project: :namespace)
+ @events = event_filter.apply_filter(@events).with_associations
@events = @events.limit(limit).offset(params[:offset] || 0)
pager_json('events/_events', @events.count)
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index b4de500fcf1..8c5605c8b4b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -20,7 +20,7 @@ class UsersController < ApplicationController
# Get user activity feed for projects common for both users
@events = @user.recent_events.
where(project_id: authorized_projects_ids).
- includes(:target, project: :namespace).limit(30)
+ with_associations.limit(30)
@title = @user.name
@title_url = user_path(@user)
diff --git a/app/models/event.rb b/app/models/event.rb
index cae7f0be85b..5579ab1dbb0 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -47,6 +47,7 @@ class Event < ActiveRecord::Base
scope :recent, -> { order("created_at DESC") }
scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
+ scope :with_associations, -> { includes(project: :namespace) }
class << self
def reset_event_cache_for(target)