Merge pull request #3739 from okriuchykhin/ok_SCI_6346

Optimize loading of project and experiment cards [SCI-6346]
This commit is contained in:
Miha Mencin 2021-12-13 16:58:08 +01:00 committed by GitHub
commit 4bfba8d691
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 28 deletions

View file

@ -274,6 +274,6 @@ module CommentHelper
end end
def has_unseen_comments?(commentable) def has_unseen_comments?(commentable)
commentable.comments.where('? = ANY (unseen_by)', current_user.id).any? commentable.comments.any? { |comment| comment.unseen_by.include?(current_user.id) }
end end
end end

View file

@ -112,14 +112,14 @@ class Activity < ApplicationRecord
def self.url_search_query(filters) def self.url_search_query(filters)
result = [] result = []
filters.each do |filter, values| filters.each do |filter, values|
result.push(values.to_query(filter)) result.push(values.map { |k, v| { k => v.collect(&:id) } }.to_query(filter))
end end
if filters[:subjects] if filters[:subjects]
subject_labels = [] subject_labels = []
filters[:subjects].each do |object, values| filters[:subjects].each do |object, values|
values.each do |value| values.each do |value|
label = object.to_s.constantize.find_by_id(value).name label = value.name
subject_labels.push({ value: value, label: label, object: object.downcase, group: '' }.as_json) subject_labels.push({ value: value.id, label: label, object: object.downcase, group: '' }.as_json)
end end
end end
result.push(subject_labels.to_query('subject_labels')) result.push(subject_labels.to_query('subject_labels'))

View file

@ -13,7 +13,7 @@ module User::TeamRoles
is_guest_of_team? is_guest_of_team?
) do |proxy, *args, &block| ) do |proxy, *args, &block|
if args[0] if args[0]
@user_team = user_teams.where(team: args[0]).take @user_team = args[0]&.user_teams&.find { |ut| ut.user == self }
@user_team ? proxy.call(*args, &block) : false @user_team ? proxy.call(*args, &block) : false
else else
false false

View file

@ -20,7 +20,7 @@ module ViewableModel
end end
def current_view_state(user) def current_view_state(user)
state = view_states.where(user: user).take state = view_states.find_by(user: user)
state || view_states.create!(user: user, state: default_view_state) state || view_states.create!(user: user, state: default_view_state)
end end
end end

View file

@ -54,8 +54,6 @@ class Project < ApplicationRecord
has_many :reports, inverse_of: :project, dependent: :destroy has_many :reports, inverse_of: :project, dependent: :destroy
has_many :report_elements, inverse_of: :project, dependent: :destroy has_many :report_elements, inverse_of: :project, dependent: :destroy
default_scope { includes(user_assignments: :user_role) }
accepts_nested_attributes_for :user_assignments, accepts_nested_attributes_for :user_assignments,
allow_destroy: true, allow_destroy: true,
reject_if: :all_blank reject_if: :all_blank

View file

@ -19,10 +19,7 @@ Canaid::Permissions.register_for(Experiment) do
# assign/reassign/unassign tags # assign/reassign/unassign tags
can :manage_experiment do |user, experiment| can :manage_experiment do |user, experiment|
experiment.permission_granted?(user, ExperimentPermissions::MANAGE) && experiment.permission_granted?(user, ExperimentPermissions::MANAGE) &&
MyModule.joins(:experiment) experiment.my_modules.all? do |my_module|
.where(experiment: experiment)
.preload(my_module_status: :my_module_status_implications)
.all? do |my_module|
if my_module.my_module_status if my_module.my_module_status
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) } my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
else else

View file

@ -26,14 +26,13 @@ Canaid::Permissions.register_for(Project) do
can :manage_project do |user, project| can :manage_project do |user, project|
project.permission_granted?(user, ProjectPermissions::MANAGE) && project.permission_granted?(user, ProjectPermissions::MANAGE) &&
MyModule.joins(experiment: :project) project.experiments.each do |experiment|
.where(experiments: { project: project }) experiment.my_modules.all? do |my_module|
.preload(my_module_status: :my_module_status_implications) if my_module.my_module_status
.all? do |my_module| my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
if my_module.my_module_status else
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) } true
else end
true
end end
end end
end end

View file

@ -35,6 +35,8 @@ class ExperimentsOverviewService
def fetch_records def fetch_records
@project.experiments @project.experiments
.joins(:project) .joins(:project)
.includes(my_modules: { my_module_status: :my_module_status_implications })
.includes(workflowimg_attachment: :blob, user_assignments: %i(user_role user))
.joins('LEFT OUTER JOIN my_modules AS active_tasks ON active_tasks.experiment_id = experiments.id ' \ .joins('LEFT OUTER JOIN my_modules AS active_tasks ON active_tasks.experiment_id = experiments.id ' \
'AND active_tasks.archived = FALSE') 'AND active_tasks.archived = FALSE')
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON active_completed_tasks.experiment_id '\ .joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON active_completed_tasks.experiment_id '\

View file

@ -86,10 +86,10 @@ class ProjectsOverviewService
def fetch_project_records def fetch_project_records
@team.projects @team.projects
.includes(user_assignments: :user_role) .includes(user_assignments: %i(user user_role), team: :user_teams)
.includes(:project_comments, experiments: { my_modules: { my_module_status: :my_module_status_implications } })
.visible_to(@user, @team) .visible_to(@user, @team)
.left_outer_joins(:project_comments) .left_outer_joins(:project_comments)
.preload(team: :user_teams)
.select('projects.*') .select('projects.*')
.select('COUNT(DISTINCT comments.id) AS comment_count') .select('COUNT(DISTINCT comments.id) AS comment_count')
.group('projects.id') .group('projects.id')
@ -97,7 +97,7 @@ class ProjectsOverviewService
def fetch_project_folder_records def fetch_project_folder_records
project_folders = @team.project_folders project_folders = @team.project_folders
.preload(team: :user_teams) .includes(team: :user_teams)
.joins('LEFT OUTER JOIN project_folders child_folders .joins('LEFT OUTER JOIN project_folders child_folders
ON child_folders.parent_folder_id = project_folders.id') ON child_folders.parent_folder_id = project_folders.id')
.left_outer_joins(:projects) .left_outer_joins(:projects)

View file

@ -74,7 +74,7 @@
</li> </li>
<!-- Open activities --> <!-- Open activities -->
<li> <li>
<a href="/global_activities?<%= Activity.url_search_query({ subjects: { Project: [project.id] } }) %>"> <a href="/global_activities?<%= Activity.url_search_query({ subjects: { Project: [project] } }) %>">
<i class="fas fa-list"></i> <i class="fas fa-list"></i>
<span><%= t('projects.index.activities_option') %></span> <span><%= t('projects.index.activities_option') %></span>
</a> </a>

View file

@ -7,7 +7,7 @@
data-restorable="<%= experiment.archived? && can_restore_experiment?(experiment) %>" data-restorable="<%= experiment.archived? && can_restore_experiment?(experiment) %>"
data-duplicable="<%= can_clone_experiment?(experiment) %>"> data-duplicable="<%= can_clone_experiment?(experiment) %>">
<div class="checkbox-cell table-cell"> <div class="checkbox-cell table-cell">
<% if can_manage_project?(experiment.project) %> <% if project_is_managable %>
<div class="sci-checkbox-container"> <div class="sci-checkbox-container">
<input value="1" type="checkbox" class="sci-checkbox experiment-card-selector"> <input value="1" type="checkbox" class="sci-checkbox experiment-card-selector">
<span class="sci-checkbox-label"></span> <span class="sci-checkbox-label"></span>

View file

@ -2,7 +2,7 @@
<div class="archived-icon-plceholder"> <div class="archived-icon-plceholder">
<i class="fas fa-archive"></i> <i class="fas fa-archive"></i>
</div> </div>
<% elsif experiment.my_modules.active.any? %> <% elsif experiment.my_modules.any?(&:active?) %>
<% if experiment.workflowimg.attached? %> <% if experiment.workflowimg.attached? %>
<div class="workflowimg-container" data-workflowimg-present="true"> <div class="workflowimg-container" data-workflowimg-present="true">
<%= render partial: 'projects/show/workflow_img.html.erb', locals: { experiment: experiment } %> <%= render partial: 'projects/show/workflow_img.html.erb', locals: { experiment: experiment } %>

View file

@ -5,9 +5,11 @@
<div class="no-results-description"><%= t('projects.index.no_results_description') %></div> <div class="no-results-description"><%= t('projects.index.no_results_description') %></div>
</div> </div>
<% else %> <% else %>
<% project_is_managable = can_manage_project?(@project) %>
<% cards.each do |card| %> <% cards.each do |card| %>
<% cache [current_user, card] do %> <% cache [current_user, card] do %>
<%= render partial: 'projects/show/experiment_card', locals: { experiment: card, project: @project } %> <%= render partial: 'projects/show/experiment_card',
locals: { experiment: card, project: @project, project_is_managable: project_is_managable } %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>