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

Fix event loading with associations

parent a6070074
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
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