mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-26 00:36:01 +08:00
Optimize loading of project and experiment cards [SCI-6346]
This commit is contained in:
parent
1e652c0a73
commit
e67b17dd6f
13 changed files with 26 additions and 28 deletions
|
@ -274,6 +274,6 @@ module CommentHelper
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -112,14 +112,14 @@ class Activity < ApplicationRecord
|
|||
def self.url_search_query(filters)
|
||||
result = []
|
||||
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
|
||||
if filters[:subjects]
|
||||
subject_labels = []
|
||||
filters[:subjects].each do |object, values|
|
||||
values.each do |value|
|
||||
label = object.to_s.constantize.find_by_id(value).name
|
||||
subject_labels.push({ value: value, label: label, object: object.downcase, group: '' }.as_json)
|
||||
label = value.name
|
||||
subject_labels.push({ value: value.id, label: label, object: object.downcase, group: '' }.as_json)
|
||||
end
|
||||
end
|
||||
result.push(subject_labels.to_query('subject_labels'))
|
||||
|
|
|
@ -13,7 +13,7 @@ module User::TeamRoles
|
|||
is_guest_of_team?
|
||||
) do |proxy, *args, &block|
|
||||
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
|
||||
else
|
||||
false
|
||||
|
@ -41,4 +41,4 @@ module User::TeamRoles
|
|||
def is_guest_of_team?(team)
|
||||
@user_team.guest?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module ViewableModel
|
|||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,8 +54,6 @@ class Project < ApplicationRecord
|
|||
has_many :reports, 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,
|
||||
allow_destroy: true,
|
||||
reject_if: :all_blank
|
||||
|
|
|
@ -19,10 +19,7 @@ Canaid::Permissions.register_for(Experiment) do
|
|||
# assign/reassign/unassign tags
|
||||
can :manage_experiment do |user, experiment|
|
||||
experiment.permission_granted?(user, ExperimentPermissions::MANAGE) &&
|
||||
MyModule.joins(:experiment)
|
||||
.where(experiment: experiment)
|
||||
.preload(my_module_status: :my_module_status_implications)
|
||||
.all? do |my_module|
|
||||
experiment.my_modules.all? do |my_module|
|
||||
if my_module.my_module_status
|
||||
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
||||
else
|
||||
|
|
|
@ -26,14 +26,13 @@ Canaid::Permissions.register_for(Project) do
|
|||
|
||||
can :manage_project do |user, project|
|
||||
project.permission_granted?(user, ProjectPermissions::MANAGE) &&
|
||||
MyModule.joins(experiment: :project)
|
||||
.where(experiments: { project: project })
|
||||
.preload(my_module_status: :my_module_status_implications)
|
||||
.all? do |my_module|
|
||||
if my_module.my_module_status
|
||||
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
||||
else
|
||||
true
|
||||
project.experiments.each do |experiment|
|
||||
experiment.my_modules.all? do |my_module|
|
||||
if my_module.my_module_status
|
||||
my_module.my_module_status.my_module_status_implications.all? { |implication| implication.call(my_module) }
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,6 +35,8 @@ class ExperimentsOverviewService
|
|||
def fetch_records
|
||||
@project.experiments
|
||||
.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 ' \
|
||||
'AND active_tasks.archived = FALSE')
|
||||
.joins('LEFT OUTER JOIN my_modules AS active_completed_tasks ON active_completed_tasks.experiment_id '\
|
||||
|
|
|
@ -86,10 +86,10 @@ class ProjectsOverviewService
|
|||
|
||||
def fetch_project_records
|
||||
@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)
|
||||
.left_outer_joins(:project_comments)
|
||||
.preload(team: :user_teams)
|
||||
.select('projects.*')
|
||||
.select('COUNT(DISTINCT comments.id) AS comment_count')
|
||||
.group('projects.id')
|
||||
|
@ -97,7 +97,7 @@ class ProjectsOverviewService
|
|||
|
||||
def fetch_project_folder_records
|
||||
project_folders = @team.project_folders
|
||||
.preload(team: :user_teams)
|
||||
.includes(team: :user_teams)
|
||||
.joins('LEFT OUTER JOIN project_folders child_folders
|
||||
ON child_folders.parent_folder_id = project_folders.id')
|
||||
.left_outer_joins(:projects)
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
</li>
|
||||
<!-- Open activities -->
|
||||
<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>
|
||||
<span><%= t('projects.index.activities_option') %></span>
|
||||
</a>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
data-restorable="<%= experiment.archived? && can_restore_experiment?(experiment) %>"
|
||||
data-duplicable="<%= can_clone_experiment?(experiment) %>">
|
||||
<div class="checkbox-cell table-cell">
|
||||
<% if can_manage_project?(experiment.project) %>
|
||||
<% if project_is_managable %>
|
||||
<div class="sci-checkbox-container">
|
||||
<input value="1" type="checkbox" class="sci-checkbox experiment-card-selector">
|
||||
<span class="sci-checkbox-label"></span>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div class="archived-icon-plceholder">
|
||||
<i class="fas fa-archive"></i>
|
||||
</div>
|
||||
<% elsif experiment.my_modules.active.any? %>
|
||||
<% elsif experiment.my_modules.any?(&:active?) %>
|
||||
<% if experiment.workflowimg.attached? %>
|
||||
<div class="workflowimg-container" data-workflowimg-present="true">
|
||||
<%= render partial: 'projects/show/workflow_img.html.erb', locals: { experiment: experiment } %>
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
<div class="no-results-description"><%= t('projects.index.no_results_description') %></div>
|
||||
</div>
|
||||
<% else %>
|
||||
<% project_is_managable = can_manage_project?(@project) %>
|
||||
<% cards.each do |card| %>
|
||||
<% 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 %>
|
||||
|
|
Loading…
Reference in a new issue