Commit 63f11a68 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix event loading with associations

parent a6070074
...@@ -22,13 +22,14 @@ class DashboardController < ApplicationController ...@@ -22,13 +22,14 @@ class DashboardController < ApplicationController
format.html format.html
format.json do format.json do
@events = Event.in_projects(current_user.authorized_projects.pluck(:id)) load_events
@events = @event_filter.apply_filter(@events).includes(:target, project: :namespace)
@events = @events.limit(20).offset(params[:offset] || 0)
pager_json("events/_events", @events.count) pager_json("events/_events", @events.count)
end end
format.atom { render layout: false } format.atom do
load_events
render layout: false
end
end end
end end
...@@ -77,4 +78,10 @@ class DashboardController < ApplicationController ...@@ -77,4 +78,10 @@ class DashboardController < ApplicationController
def load_projects def load_projects
@projects = current_user.authorized_projects.sorted_by_activity.non_archived @projects = current_user.authorized_projects.sorted_by_activity.non_archived
end 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 end
...@@ -39,13 +39,14 @@ class GroupsController < ApplicationController ...@@ -39,13 +39,14 @@ class GroupsController < ApplicationController
format.html format.html
format.json do format.json do
@events = Event.in_projects(project_ids) load_events
@events = event_filter.apply_filter(@events).includes(:target, project: :namespace)
@events = @events.limit(20).offset(params[:offset] || 0)
pager_json("events/_events", @events.count) pager_json("events/_events", @events.count)
end end
format.atom { render layout: false } format.atom do
load_events
render layout: false
end
end end
end end
...@@ -154,4 +155,10 @@ class GroupsController < ApplicationController ...@@ -154,4 +155,10 @@ class GroupsController < ApplicationController
def group_params def group_params
params.require(:group).permit(:name, :description, :path, :avatar) params.require(:group).permit(:name, :description, :path, :avatar)
end 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 end
...@@ -76,7 +76,7 @@ class ProjectsController < ApplicationController ...@@ -76,7 +76,7 @@ class ProjectsController < ApplicationController
format.json do format.json do
@events = @project.events.recent @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) @events = @events.limit(limit).offset(params[:offset] || 0)
pager_json('events/_events', @events.count) pager_json('events/_events', @events.count)
end end
......
...@@ -20,7 +20,7 @@ class UsersController < ApplicationController ...@@ -20,7 +20,7 @@ class UsersController < ApplicationController
# Get user activity feed for projects common for both users # Get user activity feed for projects common for both users
@events = @user.recent_events. @events = @user.recent_events.
where(project_id: authorized_projects_ids). where(project_id: authorized_projects_ids).
includes(:target, project: :namespace).limit(30) with_associations.limit(30)
@title = @user.name @title = @user.name
@title_url = user_path(@user) @title_url = user_path(@user)
......
...@@ -47,6 +47,7 @@ class Event < ActiveRecord::Base ...@@ -47,6 +47,7 @@ class Event < ActiveRecord::Base
scope :recent, -> { order("created_at DESC") } scope :recent, -> { order("created_at DESC") }
scope :code_push, -> { where(action: PUSHED) } scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
scope :with_associations, -> { includes(project: :namespace) }
class << self class << self
def reset_event_cache_for(target) def reset_event_cache_for(target)
......
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