mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Improve loading time of current tasks widget [SCI-7999] (#5022)
* Improve loading time of current tasks widget [SCI-7999] * Improve speed of objects search for smart annotations editor [SCI-7999]
This commit is contained in:
parent
0ad592bd5e
commit
b2ab467440
3 changed files with 11 additions and 14 deletions
|
@ -103,8 +103,7 @@ module Dashboard
|
|||
.where(projects: { archived: false })
|
||||
|
||||
if task_filters[:mode] == 'assigned'
|
||||
assigned_tasks = tasks.joins(:user_my_modules).where(user_my_modules: { user_id: current_user.id }).select(:id)
|
||||
tasks = tasks.where(id: assigned_tasks)
|
||||
tasks = tasks.joins(:user_my_modules).where(user_my_modules: { user_id: current_user.id })
|
||||
end
|
||||
|
||||
tasks = tasks.where(my_module_status_id: task_filters[:statuses]) if task_filters[:statuses].present?
|
||||
|
|
|
@ -7,7 +7,7 @@ module SearchableByNameModel
|
|||
def self.search_by_name(user, teams = [], query = nil, options = {})
|
||||
return if user.blank? || teams.blank?
|
||||
|
||||
sql_q = viewable_by_user(user, teams)
|
||||
sql_q = self
|
||||
|
||||
if options[:intersect]
|
||||
query_array = query.gsub(/[[:space:]]+/, ' ').split(' ')
|
||||
|
@ -18,6 +18,8 @@ module SearchableByNameModel
|
|||
sql_q = sql_q.where_attributes_like("#{table_name}.name", query, options)
|
||||
end
|
||||
|
||||
sql_q = sql_q.where(id: viewable_by_user(user, teams))
|
||||
|
||||
sql_q.limit(Constants::SEARCH_LIMIT)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,19 +98,15 @@ class Project < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.viewable_by_user(user, teams)
|
||||
# Admins see all projects in the team
|
||||
# Member of the projects can view
|
||||
# If project is visible everyone from the team can view it
|
||||
# Team owners see all projects in the team
|
||||
owner_role = UserRole.find_predefined_owner_role
|
||||
projects = Project.where(team: teams)
|
||||
.left_outer_joins(:team, user_assignments: :user_role)
|
||||
.joins("LEFT OUTER JOIN user_assignments team_user_assignments "\
|
||||
"ON team_user_assignments.assignable_type = 'Team' "\
|
||||
projects = Project.left_outer_joins(:team, user_assignments: :user_role)
|
||||
.joins("LEFT OUTER JOIN user_assignments team_user_assignments " \
|
||||
"ON team_user_assignments.assignable_type = 'Team' " \
|
||||
"AND team_user_assignments.assignable_id = team.id")
|
||||
projects.where(visibility: visibilities[:visible])
|
||||
.or(projects.where(team: { team_user_assignments: { user_id: user, user_role_id: owner_role } }))
|
||||
.or(projects.with_granted_permissions(user, ProjectPermissions::READ))
|
||||
.distinct
|
||||
.where(team: teams)
|
||||
projects.where(team: { team_user_assignments: { user_id: user, user_role_id: owner_role } })
|
||||
.or(projects.with_granted_permissions(user, ProjectPermissions::READ)).distinct
|
||||
end
|
||||
|
||||
def self.filter_by_teams(teams = [])
|
||||
|
|
Loading…
Reference in a new issue