diff --git a/api/caching/tasks.py b/api/caching/tasks.py index 0af20b401c0..d6e046267cb 100644 --- a/api/caching/tasks.py +++ b/api/caching/tasks.py @@ -122,15 +122,15 @@ def update_storage_usage_cache(target_id, target_guid, per_page=500000): def compute_storage_usage_total(target_obj, per_page=500000): - sql = """SELECT count(file_page.size), sum(file_page.size) from ( - SELECT version.size AS size - FROM osf_basefileversionsthrough AS obfnv - LEFT JOIN osf_basefilenode AS file ON obfnv.basefilenode_id = file.id - LEFT JOIN osf_fileversion AS version ON obfnv.fileversion_id = version.id + sql = """ + SELECT count(size), sum(size) from + (SELECT size FROM osf_basefileversionsthrough AS obfnv + LEFT JOIN osf_basefilenode file ON obfnv.basefilenode_id = file.id + LEFT JOIN osf_fileversion version ON obfnv.fileversion_id = version.id WHERE file.provider = 'osfstorage' AND file.deleted_on IS NULL - AND file.target_object_id=%(target_id)s - AND file.target_content_type_id = %(target_content_type_id)s + AND file.target_object_id=%(target_pk)s + AND file.target_content_type_id = %(target_content_type_pk)s ORDER BY version.id LIMIT %(per_page)s OFFSET %(offset)s ) file_page @@ -142,8 +142,8 @@ def compute_storage_usage_total(target_obj, per_page=500000): while last_count: cursor.execute( sql, { - 'target_id': target_obj.pk, - 'target_content_type_id': ContentType.objects.get_for_model(target_obj).pk, + 'target_pk': target_obj.pk, + 'target_content_type_pk': ContentType.objects.get_for_model(target_obj).pk, 'per_page': per_page, 'offset': offset, },