Improve activities loading speed [SCI-6345]

This commit is contained in:
Oleksii Kriuchykhin 2021-12-09 19:28:27 +01:00
parent 9ff71ad651
commit 8f1b201061
2 changed files with 2 additions and 4 deletions

View file

@ -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 })

View file

@ -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")