simplify harvest_clear queries so they do not lock on big db
This commit is contained in:
parent
a2b8ab1994
commit
1714e55110
|
@ -103,17 +103,12 @@ def harvest_source_clear(context,data_dict):
|
|||
|
||||
harvest_source_id = source.id
|
||||
|
||||
sql = '''begin;
|
||||
|
||||
update package set state = 'to_delete' where id in (select package_id from harvest_object where harvest_source_id = '{harvest_source_id}') ;
|
||||
|
||||
--harvest
|
||||
sql = '''begin; update package set state = 'to_delete' where id in (select package_id from harvest_object where harvest_source_id = '{harvest_source_id}');
|
||||
delete from harvest_object_error where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}');
|
||||
delete from harvest_object_extra where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}');
|
||||
delete from harvest_object where harvest_source_id = '{harvest_source_id}';
|
||||
delete from harvest_gather_error where harvest_job_id in (select id from harvest_job where source_id = '{harvest_source_id}');
|
||||
delete from harvest_job where source_id = '{harvest_source_id}';
|
||||
|
||||
delete from package_role where package_id in (select id from package where state = 'to_delete' );
|
||||
delete from user_object_role where id not in (select user_object_role_id from package_role) and context = 'Package';
|
||||
delete from resource_revision where resource_group_id in (select id from resource_group where package_id in (select id from package where state = 'to_delete'));
|
||||
|
@ -122,15 +117,12 @@ def harvest_source_clear(context,data_dict):
|
|||
delete from member_revision where table_id in (select id from package where state = 'to_delete');
|
||||
delete from package_extra_revision where package_id in (select id from package where state = 'to_delete');
|
||||
delete from package_revision where id in (select id from package where state = 'to_delete');
|
||||
|
||||
delete from package_tag where id not in (select id from package_tag_revision);
|
||||
delete from resource where id not in (select id from resource_revision);
|
||||
delete from package_extra where id not in (select id from package_extra_revision);
|
||||
delete from member where id not in (select id from member_revision);
|
||||
delete from resource_group where id not in (select id from resource_group_revision);
|
||||
delete from package where id not in (select id from package_revision);
|
||||
|
||||
commit;'''.format(harvest_source_id=harvest_source_id)
|
||||
delete from package_tag where id in (select id from package where state = 'to_delete');
|
||||
delete from resource where id in (select id from package where state = 'to_delete');
|
||||
delete from package_extra where id in (select id from package where state = 'to_delete');
|
||||
delete from member where id in (select id from package where state = 'to_delete');
|
||||
delete from resource_group where id in (select id from package where state = 'to_delete');
|
||||
delete from package where id in (select id from package where state = 'to_delete'); commit;'''.format(harvest_source_id=harvest_source_id)
|
||||
|
||||
model = context['model']
|
||||
|
||||
|
|
Loading…
Reference in New Issue