Commit 7f428e30 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Remove partial archive when deleting an upload. #434

parent afd85df9
Pipeline #86217 passed with stages
in 26 minutes and 47 seconds
......@@ -800,6 +800,12 @@ def read_partial_archive_from_mongo(entry_id: str, as_dict=False) -> Union[Entry
return EntryArchive.m_from_dict(archive_dict)
def delete_partial_archives_from_mongo(entry_ids: List[str]):
mongo_db = infrastructure.mongo_client[config.mongo.db_name]
mongo_collection = mongo_db['archive']
mongo_collection.delete_many(dict(_id={'$in': entry_ids}))
def read_partial_archives_from_mongo(entry_ids: List[str], as_dict=False) -> Dict[str, Union[EntryArchive, Dict]]:
'''
Reads the partial archives for a set of entries of the same upload.
......
......@@ -47,7 +47,7 @@ from nomad.processing.base import Proc, process, task, PENDING, SUCCESS, FAILURE
from nomad.parsing.parsers import parser_dict, match_parser
from nomad.normalizing import normalizers
from nomad.datamodel import EntryArchive, EditableUserMetadata
from nomad.archive import query_archive, write_partial_archive_to_mongo
from nomad.archive import query_archive, write_partial_archive_to_mongo, delete_partial_archives_from_mongo
from nomad.datamodel.encyclopedia import EncyclopediaMetadata
......@@ -772,6 +772,13 @@ class Upload(Proc):
upload_size=self.upload_files.size):
search.delete_upload(self.upload_id)
with utils.timer(
logger, 'upload partial archives', step='files',
upload_size=self.upload_files.size):
calc_ids = [calc.calc_id for calc in Calc.objects(upload_id=self.upload_id)]
delete_partial_archives_from_mongo(calc_ids)
with utils.timer(
logger, 'upload deleted', step='files',
upload_size=self.upload_files.size):
......@@ -782,7 +789,7 @@ class Upload(Proc):
@process
def delete_upload(self):
'''
Deletes of the upload, including its processing state and
Deletes the upload, including its processing state and
staging files. This starts the celery process of deleting the upload.
'''
self.delete_upload_local()
......
......@@ -306,8 +306,14 @@ class TestUploads:
rv = api.get('/uploads/%s' % upload_id, headers=test_user_auth)
assert rv.status_code == 404
assert Upload.objects(upload_id=upload_id).first() is None
assert Calc.objects(upload_id=upload_id).count() is 0
mongo_db = infrastructure.mongo_client[config.mongo.db_name]
mongo_collection = mongo_db['archive']
assert mongo_collection.find({}).count() == 0
upload_files = UploadFiles.get(upload_id)
assert upload_files is None or isinstance(upload_files, PublicUploadFiles)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment