diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-30 14:26:19 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-30 14:26:19 +0200 |
commit | d075df56d3cfb15a5d11550d86229f5b8001fbe7 (patch) | |
tree | 7ba075db3f2d4f624e818331e3a1085361dd0cbd | |
parent | f45345edb33f1129aabb58976ae2e6812387eb7d (diff) | |
download | gitlab-ce-d075df56d3cfb15a5d11550d86229f5b8001fbe7.tar.gz |
Improve perfomance of removeing group
-rw-r--r-- | app/controllers/admin/groups_controller.rb | 2 | ||||
-rw-r--r-- | app/models/group.rb | 4 | ||||
-rw-r--r-- | app/models/users_project.rb | 19 | ||||
-rw-r--r-- | app/roles/team.rb | 3 |
4 files changed, 27 insertions, 1 deletions
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 54c69138a3a..90dbda3eeea 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -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.' diff --git a/app/models/group.rb b/app/models/group.rb index f16c70a6864..8ba92980a9b 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -29,4 +29,8 @@ class Group < Namespace def human_name name end + + def truncate_teams + UsersProject.truncate_teams(project_ids) + end end diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 23b83f5203d..b8aacb32953 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -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 diff --git a/app/roles/team.rb b/app/roles/team.rb index 0e431244590..a228e2176a4 100644 --- a/app/roles/team.rb +++ b/app/roles/team.rb @@ -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 |