Added soft-delete to the files schema.

This allows us to soft-delete orphan files, at least until we know
that the orphan file detection is solid and can really be trusted.
This commit is contained in:
2017-09-13 11:05:35 +02:00
parent ce59bc3335
commit 16bf193b0e
2 changed files with 4 additions and 2 deletions

View File

@@ -720,11 +720,12 @@ tokens = {
} }
files = { files = {
'schema': files_schema,
'resource_methods': ['GET', 'POST'], 'resource_methods': ['GET', 'POST'],
'item_methods': ['GET', 'PATCH'], 'item_methods': ['GET', 'PATCH'],
'public_methods': ['GET'], 'public_methods': ['GET'],
'public_item_methods': ['GET'], 'public_item_methods': ['GET'],
'schema': files_schema 'soft_delete': True,
} }
groups = { groups = {

View File

@@ -544,7 +544,8 @@ def _find_orphan_files(project_id: bson.ObjectId) -> typing.Set[bson.ObjectId]:
# Get all file IDs that belong to this project. # Get all file IDs that belong to this project.
files_coll = current_app.db('files') files_coll = current_app.db('files')
cursor = files_coll.find({'project': project_id}, projection={'_id': 1}) file_filter = {'project': project_id, '_deleted': {'$ne': True}}
cursor = files_coll.find(file_filter, projection={'_id': 1})
file_ids = {doc['_id'] for doc in cursor} file_ids = {doc['_id'] for doc in cursor}
if not file_ids: if not file_ids:
log.debug('Project %s has no files', project_id) log.debug('Project %s has no files', project_id)