Skip to content

Commit e2b41e3

Browse files
authored
Merge pull request #886 from hubmapconsortium/yuanzhou/fix-put-timeout
Yuanzhou/fix put timeout
2 parents bb9760a + bf23699 commit e2b41e3

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

src/app.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5342,37 +5342,54 @@ def require_json(request):
53425342
"""
53435343
def delete_cache(id):
53445344
if MEMCACHED_MODE:
5345-
# First delete the target entity cache
53465345
entity_dict = query_target_entity(id, get_internal_token())
53475346
entity_uuid = entity_dict['uuid']
5348-
5349-
# Delete the cache of all the descendants
5350-
descendant_uuids = schema_neo4j_queries.get_descendants(neo4j_driver_instance, entity_uuid , 'uuid')
5351-
5352-
# If the target entity is Collection, delete the cache for each of its associated
5353-
# Datasets and Publications (via [:IN_COLLECTION]) as well as just Publications (via [:USES_DATA])
5347+
entity_type = entity_dict['entity_type']
5348+
descendant_uuids = []
5349+
collection_dataset_uuids = []
5350+
upload_dataset_uuids = []
5351+
collection_uuids = []
5352+
dataset_upload_dict = {}
5353+
publication_collection_dict = {}
5354+
5355+
# Determine the associated cache keys based on the entity type
5356+
# To reduce unnecessary Neo4j lookups that may cause timeout on the PUT call
5357+
5358+
# For Donor/Datasets/Sample/Publication, delete the cache of all the descendants
5359+
if entity_type in ['Donor', 'Sample', 'Dataset', 'Publication']:
5360+
descendant_uuids = schema_neo4j_queries.get_descendants(neo4j_driver_instance, entity_uuid , 'uuid')
5361+
5362+
# For Collection/Epicollection, delete the cache for each of its associated datasets (via [:IN_COLLECTION])
5363+
if schema_manager.entity_type_instanceof(entity_type, 'Collection'):
5364+
collection_dataset_uuids = schema_neo4j_queries.get_collection_associated_datasets(neo4j_driver_instance, entity_uuid , 'uuid')
5365+
5366+
# For Upload, delete the cache for each of its associated Datasets (via [:IN_UPLOAD])
5367+
if entity_type == 'Upload':
5368+
upload_dataset_uuids = schema_neo4j_queries.get_upload_datasets(neo4j_driver_instance, entity_uuid , 'uuid')
5369+
5370+
# For Dataset, delete the associated Collections cache and single Upload cache
5371+
if entity_type == 'Dataset':
5372+
collection_uuids = schema_neo4j_queries.get_dataset_collections(neo4j_driver_instance, entity_uuid , 'uuid')
5373+
dataset_upload_dict = schema_neo4j_queries.get_dataset_upload(neo4j_driver_instance, entity_uuid)
5374+
5375+
# For Publication, delete cache of the associated collection
53545376
# NOTE: As of 5/30/2025, the [:USES_DATA] workaround has been deprecated.
53555377
# Still keep it in the code until further decision - Zhou
5356-
collection_dataset_uuids = schema_neo4j_queries.get_collection_associated_datasets(neo4j_driver_instance, entity_uuid , 'uuid')
5357-
5358-
# If the target entity is Upload, delete the cache for each of its associated Datasets (via [:IN_UPLOAD] relationship)
5359-
upload_dataset_uuids = schema_neo4j_queries.get_upload_datasets(neo4j_driver_instance, entity_uuid , 'uuid')
5360-
5361-
# If the target entity is Datasets/Publication, delete the associated Collections cache, Upload cache
5362-
collection_uuids = schema_neo4j_queries.get_dataset_collections(neo4j_driver_instance, entity_uuid , 'uuid')
5363-
collection_dict = schema_neo4j_queries.get_publication_associated_collection(neo4j_driver_instance, entity_uuid)
5364-
upload_dict = schema_neo4j_queries.get_dataset_upload(neo4j_driver_instance, entity_uuid)
5365-
5378+
if entity_type == 'Publication':
5379+
publication_collection_dict = schema_neo4j_queries.get_publication_associated_collection(neo4j_driver_instance, entity_uuid)
5380+
53665381
# We only use uuid in the cache key acorss all the cache types
53675382
uuids_list = [entity_uuid] + descendant_uuids + collection_dataset_uuids + upload_dataset_uuids + collection_uuids
53685383

5369-
# It's possible no linked collection or upload
5370-
if collection_dict:
5371-
uuids_list.append(collection_dict['uuid'])
5384+
# It's possible the target dataset has no linked upload
5385+
if dataset_upload_dict:
5386+
uuids_list.append(dataset_upload_dict['uuid'])
53725387

5373-
if upload_dict:
5374-
uuids_list.append(upload_dict['uuid'])
5388+
# It's possible the target publicaiton has no associated collection
5389+
if publication_collection_dict:
5390+
uuids_list.append(publication_collection_dict['uuid'])
53755391

5392+
# Final batch delete
53765393
schema_manager.delete_memcached_cache(uuids_list)
53775394

53785395

0 commit comments

Comments
 (0)