Improve perfomance of removeing group
This commit is contained in:
parent
f45345edb3
commit
d075df56d3
4 changed files with 27 additions and 1 deletions
|
@ -73,6 +73,8 @@ class Admin::GroupsController < AdminController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@group.truncate_teams
|
||||
|
||||
@group.destroy
|
||||
|
||||
redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
|
||||
|
|
|
@ -29,4 +29,8 @@ class Group < Namespace
|
|||
def human_name
|
||||
name
|
||||
end
|
||||
|
||||
def truncate_teams
|
||||
UsersProject.truncate_teams(project_ids)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,6 +56,25 @@ class UsersProject < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
def truncate_teams(project_ids)
|
||||
UsersProject.transaction do
|
||||
users_projects = UsersProject.where(project_id: project_ids)
|
||||
users_projects.each do |users_project|
|
||||
users_project.skip_git = true
|
||||
users_project.destroy
|
||||
end
|
||||
Gitlab::Gitolite.new.update_repositories(Project.where(id: project_ids))
|
||||
end
|
||||
|
||||
true
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
def truncate_team project
|
||||
truncate_teams [project.id]
|
||||
end
|
||||
|
||||
def import_team(source_project, target_project)
|
||||
source_team = source_project.users_projects.all
|
||||
target_team = target_project.users_projects.all
|
||||
|
|
|
@ -47,7 +47,8 @@ module Team
|
|||
UsersProject.bulk_delete(self, users_ids)
|
||||
end
|
||||
|
||||
# Remove all users from project team
|
||||
def truncate_team
|
||||
UsersProject.bulk_delete(self, self.users.map(&:id))
|
||||
UsersProject.truncate_team(self)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue