From 8f1b20106183845dccccc1472d408a6344996f66 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 9 Dec 2021 19:28:27 +0100 Subject: [PATCH] Improve activities loading speed [SCI-6345] --- app/models/concerns/assignable.rb | 2 -- app/services/activities_service.rb | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/assignable.rb b/app/models/concerns/assignable.rb index 022e3a797..78ebbed74 100644 --- a/app/models/concerns/assignable.rb +++ b/app/models/concerns/assignable.rb @@ -10,8 +10,6 @@ module Assignable has_many :user_assignments, as: :assignable, dependent: :destroy - default_scope { includes(user_assignments: :user_role).distinct } - scope :readable_by_user, lambda { |user| joins(user_assignments: :user_role) .where(user_assignments: { user: user }) diff --git a/app/services/activities_service.rb b/app/services/activities_service.rb index f46c95a9d..f9f19264f 100644 --- a/app/services/activities_service.rb +++ b/app/services/activities_service.rb @@ -5,9 +5,9 @@ class ActivitiesService # Create condition for view permissions checking first visible_teams = user.teams.where(id: teams) visible_projects = Project.viewable_by_user(user, visible_teams) - visible_by_teams = Activity.where(project: nil, team_id: visible_teams.pluck(:id)) + visible_by_teams = Activity.where(project: nil, team_id: visible_teams.select(:id)) .order(created_at: :desc) - visible_by_projects = Activity.where(project_id: visible_projects.pluck(:id)) + visible_by_projects = Activity.where(project_id: visible_projects.select(:id)) .order(created_at: :desc) query = Activity.from("((#{visible_by_teams.to_sql}) UNION ALL (#{visible_by_projects.to_sql})) AS activities")