X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/685db28b50225cde7dbb03aa2275f7a165d888a3..28da710485559dac72a8b2380dce1973a5e2893a:/services/api/app/controllers/sys_controller.rb diff --git a/services/api/app/controllers/sys_controller.rb b/services/api/app/controllers/sys_controller.rb index ecc02e83dc..7d20cf77fd 100644 --- a/services/api/app/controllers/sys_controller.rb +++ b/services/api/app/controllers/sys_controller.rb @@ -7,38 +7,41 @@ class SysController < ApplicationController skip_before_action :render_404_if_no_object before_action :admin_required - def sweep_trash + def trash_sweep act_as_system_user do # Sweep trashed collections Collection. where('delete_at is not null and delete_at < statement_timestamp()'). + in_batches(of: 15). destroy_all Collection. where('is_trashed = false and trash_at < statement_timestamp()'). + in_batches(of: 15). update_all('is_trashed = true') - # Sweep trashed projects and their contents + # Sweep trashed projects and their contents (as well as role + # groups that were trashed before #18340 when that was + # disallowed) Group. - where({group_class: 'project'}). where('delete_at is not null and delete_at < statement_timestamp()').each do |project| delete_project_and_contents(project.uuid) end Group. - where({group_class: 'project'}). where('is_trashed = false and trash_at < statement_timestamp()'). update_all('is_trashed = true') # Sweep expired tokens ActiveRecord::Base.connection.execute("DELETE from api_client_authorizations where expires_at <= statement_timestamp()") end + head :no_content end protected def delete_project_and_contents(p_uuid) p = Group.find_by_uuid(p_uuid) - if !p || p.group_class != 'project' - raise "can't sweep group '#{p_uuid}', it may not exist or not be a project" + if !p + raise "can't sweep group '#{p_uuid}', it may not exist" end # First delete sub projects Group.where({group_class: 'project', owner_uuid: p_uuid}).each do |sub_project| @@ -49,7 +52,7 @@ class SysController < ApplicationController skipped_classes = ['Group', 'User'] ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass| if !skipped_classes.include?(klass.name) && klass.columns.collect(&:name).include?('owner_uuid') - klass.where({owner_uuid: p_uuid}).destroy_all + klass.where({owner_uuid: p_uuid}).in_batches(of: 15).destroy_all end end # Finally delete the project itself