mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-08 07:21:03 +08:00
Merge pull request #7999 from andrej-scinote/aj_SCI_11178
Improve activities loading speed [SCI-11178]
This commit is contained in:
commit
ffe4e57639
4 changed files with 10 additions and 13 deletions
|
|
@ -69,8 +69,7 @@ class Experiment < ApplicationRecord
|
|||
)
|
||||
teams = options[:teams] || current_team || user.teams.select(:id)
|
||||
|
||||
new_query = distinct.with_granted_permissions(user, ExperimentPermissions::READ)
|
||||
.where(user_assignments: { team: teams })
|
||||
new_query = distinct.viewable_by_user(user, teams)
|
||||
.where_attributes_like_boolean(SEARCHABLE_ATTRIBUTES, query, options)
|
||||
|
||||
new_query = new_query.joins(:project).active.where(projects: { archived: false }) unless include_archived
|
||||
|
|
@ -80,7 +79,7 @@ class Experiment < ApplicationRecord
|
|||
|
||||
def self.viewable_by_user(user, teams)
|
||||
with_granted_permissions(user, ExperimentPermissions::READ)
|
||||
.where(project: Project.viewable_by_user(user, teams))
|
||||
.where(user_assignments: { team: teams })
|
||||
end
|
||||
|
||||
def self.with_children_viewable_by_user(user)
|
||||
|
|
|
|||
|
|
@ -116,8 +116,7 @@ class MyModule < ApplicationRecord
|
|||
teams = options[:teams] || current_team || user.teams.select(:id)
|
||||
|
||||
new_query = distinct.left_joins(:task_comments, my_module_tags: :tag, user_my_modules: :user)
|
||||
.with_granted_permissions(user, MyModulePermissions::READ)
|
||||
.where(user_assignments: { team: teams })
|
||||
.viewable_by_user(user, teams)
|
||||
.where_attributes_like_boolean(SEARCHABLE_ATTRIBUTES, query, options)
|
||||
|
||||
unless include_archived
|
||||
|
|
@ -130,7 +129,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
def self.viewable_by_user(user, teams)
|
||||
with_granted_permissions(user, MyModulePermissions::READ)
|
||||
.where(experiment: Experiment.viewable_by_user(user, teams))
|
||||
.where(user_assignments: { team: teams })
|
||||
end
|
||||
|
||||
def self.filter_by_teams(teams = [])
|
||||
|
|
|
|||
|
|
@ -238,8 +238,7 @@ class Protocol < ApplicationRecord
|
|||
|
||||
def self.viewable_by_user_my_module_protocols(user, teams)
|
||||
distinct.joins(:my_module)
|
||||
.where(my_modules: MyModule.with_granted_permissions(user, MyModulePermissions::READ)
|
||||
.where(user_assignments: { team: teams }))
|
||||
.where(my_modules: MyModule.viewable_by_user(user, teams))
|
||||
end
|
||||
|
||||
def self.filter_by_teams(teams = [])
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
class ActivitiesService
|
||||
def self.load_activities(user, teams, filters = {})
|
||||
# Create condition for view permissions checking first
|
||||
visible_teams = user.teams.where(id: teams)
|
||||
visible_projects = Project.viewable_by_user(user, visible_teams)
|
||||
teams = user.teams.where(id: teams).pluck(:id)
|
||||
visible_projects = Project.viewable_by_user(user, teams)
|
||||
visible_my_modules = MyModule.viewable_by_user(user, teams)
|
||||
|
||||
# Temporary solution until handling of deleted subjects is fully implemented
|
||||
visible_repository_teams = visible_teams.with_user_permission(user, RepositoryPermissions::READ)
|
||||
visible_by_teams = Activity.where(project: nil, team_id: visible_teams.select(:id))
|
||||
visible_repository_teams = user.teams.where(id: teams).with_user_permission(user, RepositoryPermissions::READ)
|
||||
visible_by_teams = Activity.where(project: nil, team_id: teams)
|
||||
.where.not(subject_type: %w(RepositoryBase RepositoryRow Protocol))
|
||||
.order(created_at: :desc)
|
||||
visible_by_repositories = Activity.where(subject_type: %w(RepositoryBase RepositoryRow), team_id: visible_repository_teams.select(:id))
|
||||
|
|
@ -19,7 +19,7 @@ class ActivitiesService
|
|||
.order(created_at: :desc)
|
||||
|
||||
visible_by_experiments = Activity.where(subject_type: 'Experiment')
|
||||
.where(subject_id: Experiment.viewable_by_user(user, visible_teams))
|
||||
.where(subject_id: Experiment.viewable_by_user(user, teams))
|
||||
.order(created_at: :desc)
|
||||
|
||||
visible_by_my_modules = Activity.where("subject_id IN (?) AND subject_type = 'MyModule' OR " \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue