mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 13:13:22 +08:00
Merge pull request #4423 from okriuchykhin/ok_SCI_7180
Improve speed of group unassignment job as it is executed in foreground [SCI-7180]
This commit is contained in:
commit
f62e4e8509
3 changed files with 22 additions and 12 deletions
|
@ -9,7 +9,7 @@ module UserAssignments
|
||||||
@assigned_by = assigned_by
|
@assigned_by = assigned_by
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
team.users.where.not(id: assigned_by.id).find_each do |user|
|
team.users.where.not(id: assigned_by).find_each do |user|
|
||||||
user_assignment = UserAssignment.find_or_initialize_by(
|
user_assignment = UserAssignment.find_or_initialize_by(
|
||||||
user: user,
|
user: user,
|
||||||
assignable: project
|
assignable: project
|
||||||
|
|
|
@ -7,20 +7,30 @@ module UserAssignments
|
||||||
def perform(project)
|
def perform(project)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
user_assignments = project.user_assignments.where(assigned: :automatically)
|
user_assignments = project.user_assignments.where(assigned: :automatically)
|
||||||
users = User.find(user_assignments.pluck(:user_id))
|
users = User.where(id: user_assignments.select(:user_id))
|
||||||
|
|
||||||
remove_users_from_experiments_and_my_modules(project, users)
|
remove_users_from_my_modules(project, users)
|
||||||
UserAssignment.where(user: users, assignable: project).destroy_all
|
remove_users_from_experiments(project, users)
|
||||||
|
user_assignments.destroy_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_users_from_experiments_and_my_modules(project, users)
|
def remove_users_from_experiments(project, users)
|
||||||
project.experiments.each do |experiment|
|
experiments = project.experiments.joins(:user_assignments).where(user_assignments: { user: users })
|
||||||
experiment.my_modules.each do |my_module|
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
UserAssignment.where(user: users, assignable: my_module).destroy_all
|
UserAssignment.where(assignable_type: 'Experiment', assignable_id: experiments, user: users).delete_all
|
||||||
end
|
experiments.update_all(updated_at: Time.current)
|
||||||
UserAssignment.where(user: users, assignable: experiment).destroy_all
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_users_from_my_modules(project, users)
|
||||||
|
my_modules = MyModule.joins(:user_assignments, experiment: :project)
|
||||||
|
.where(user_assignments: { user: users })
|
||||||
|
.where(projects: project)
|
||||||
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
|
UserAssignment.where(assignable_type: 'MyModule', assignable_id: my_modules, user: users).delete_all
|
||||||
|
my_modules.update_all(updated_at: Time.current)
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -326,7 +326,7 @@ class Project < ApplicationRecord
|
||||||
UserAssignments::GroupAssignmentJob.perform_now(
|
UserAssignments::GroupAssignmentJob.perform_now(
|
||||||
team,
|
team,
|
||||||
self,
|
self,
|
||||||
created_by
|
last_modified_by || created_by
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue