@@ -807,11 +807,6 @@ def get_dataset_upload(property_key, normalized_type, user_token, existing_data_
807807 A dictionary that contains all existing entity properties
808808new_data_dict : dict
809809 A merged dictionary that contains all possible input data to be used
810-
811- Returns
812- -------
813- str: The target property key
814- str: The uuid string of source entity
815810"""
816811def link_dataset_to_direct_ancestors (property_key , normalized_type , user_token , existing_data_dict , new_data_dict ):
817812 if 'uuid' not in existing_data_dict :
@@ -820,14 +815,19 @@ def link_dataset_to_direct_ancestors(property_key, normalized_type, user_token,
820815 if 'direct_ancestor_uuids' not in existing_data_dict :
821816 raise KeyError ("Missing 'direct_ancestor_uuids' key in 'existing_data_dict' during calling 'link_dataset_to_direct_ancestors()' trigger method." )
822817
818+ dataset_uuid = existing_data_dict ['uuid' ]
823819 direct_ancestor_uuids = existing_data_dict ['direct_ancestor_uuids' ]
824820
825821 # Generate property values for Activity node
826822 activity_data_dict = schema_manager .generate_activity_data (normalized_type , user_token , existing_data_dict )
827823
828824 try :
829825 # Create a linkage (via one Activity node) between the dataset node and its direct ancestors in neo4j
830- schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], direct_ancestor_uuids , activity_data_dict )
826+ schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), dataset_uuid , direct_ancestor_uuids , activity_data_dict )
827+
828+ # Delete the cache of this dataset if any cache exists
829+ # Because the `Dataset.direct_ancestors` field
830+ schema_manager .delete_memcached_cache ([dataset_uuid ])
831831 except TransactionError :
832832 # No need to log
833833 raise
@@ -847,11 +847,6 @@ def link_dataset_to_direct_ancestors(property_key, normalized_type, user_token,
847847 A dictionary that contains all existing entity properties
848848new_data_dict : dict
849849 A merged dictionary that contains all possible input data to be used
850-
851- Returns
852- -------
853- str: The target property key
854- str: The uuid string of source entity
855850"""
856851def link_collection_to_datasets (property_key , normalized_type , user_token , existing_data_dict , new_data_dict ):
857852 if 'uuid' not in existing_data_dict :
@@ -860,13 +855,19 @@ def link_collection_to_datasets(property_key, normalized_type, user_token, exist
860855 if 'dataset_uuids' not in existing_data_dict :
861856 raise KeyError ("Missing 'dataset_uuids' key in 'existing_data_dict' during calling 'link_collection_to_datasets()' trigger method." )
862857
858+ collection_uuid = existing_data_dict ['uuid' ]
863859 dataset_uuids = existing_data_dict ['dataset_uuids' ]
864860
865861 try :
866862 # Create a linkage (without an Activity node) between the Collection node and each Dataset it contains.
867863 schema_neo4j_queries .link_collection_to_datasets (neo4j_driver = schema_manager .get_neo4j_driver_instance ()
868864 ,collection_uuid = existing_data_dict ['uuid' ]
869865 ,dataset_uuid_list = dataset_uuids )
866+
867+ # Delete the cache of each associated dataset and the collection itself if any cache exists
868+ # Because the `Dataset.collecctions` field and `Collection.datasets` field
869+ uuids_list = [collection_uuid ] + dataset_uuids
870+ schema_manager .delete_memcached_cache (uuids_list )
870871 except TransactionError as te :
871872 # No need to log
872873 raise
@@ -976,11 +977,6 @@ def get_local_directory_rel_path(property_key, normalized_type, user_token, exis
976977 A dictionary that contains all existing entity properties
977978new_data_dict : dict
978979 A merged dictionary that contains all possible input data to be used
979-
980- Returns
981- -------
982- str: The target property key
983- str: The uuid string of source entity
984980"""
985981def link_to_previous_revision (property_key , normalized_type , user_token , existing_data_dict , new_data_dict ):
986982 if 'uuid' not in existing_data_dict :
@@ -989,9 +985,17 @@ def link_to_previous_revision(property_key, normalized_type, user_token, existin
989985 if 'previous_revision_uuid' not in existing_data_dict :
990986 raise KeyError ("Missing 'previous_revision_uuid' key in 'existing_data_dict' during calling 'link_to_previous_revision()' trigger method." )
991987
988+ entity_uuid = existing_data_dict ['uuid' ]
989+ previous_uuid = existing_data_dict ['previous_revision_uuid' ]
990+
992991 # Create a revision reltionship from this new Dataset node and its previous revision of dataset node in neo4j
993992 try :
994- schema_neo4j_queries .link_entity_to_previous_revision (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], existing_data_dict ['previous_revision_uuid' ])
993+ schema_neo4j_queries .link_entity_to_previous_revision (schema_manager .get_neo4j_driver_instance (), entity_uuid , previous_uuid )
994+
995+ # Delete the cache of each associated dataset if any cache exists
996+ # Because the `Dataset.previous_revision_uuid` and `Dataset.next_revision_uuid` fields
997+ uuids_list = [entity_uuid , previous_uuid ]
998+ schema_manager .delete_memcached_cache (uuids_list )
995999 except TransactionError :
9961000 # No need to log
9971001 raise
@@ -1392,6 +1396,8 @@ def link_donor_to_lab(property_key, normalized_type, user_token, existing_data_d
13921396 # Create a linkage (via Activity node)
13931397 # between the Donor node and the parent Lab node in neo4j
13941398 schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], direct_ancestor_uuids , activity_data_dict )
1399+
1400+ # No need to delete any cache here since this is one-time donor creation
13951401 except TransactionError :
13961402 # No need to log
13971403 raise
@@ -1507,6 +1513,8 @@ def link_sample_to_direct_ancestor(property_key, normalized_type, user_token, ex
15071513 if 'direct_ancestor_uuid' not in existing_data_dict :
15081514 raise KeyError ("Missing 'direct_ancestor_uuid' key in 'existing_data_dict' during calling 'link_sample_to_direct_ancestor()' trigger method." )
15091515
1516+ sample_uuid = existing_data_dict ['uuid' ]
1517+
15101518 # Build a list of direct ancestor uuids
15111519 # Only one uuid in the list in this case
15121520 direct_ancestor_uuids = [existing_data_dict ['direct_ancestor_uuid' ]]
@@ -1517,7 +1525,11 @@ def link_sample_to_direct_ancestor(property_key, normalized_type, user_token, ex
15171525 try :
15181526 # Create a linkage (via Activity node)
15191527 # between the Sample node and the source entity node in neo4j
1520- schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], direct_ancestor_uuids , activity_data_dict )
1528+ schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), sample_uuid , direct_ancestor_uuids , activity_data_dict )
1529+
1530+ # Delete the cache of sample if any cache exists
1531+ # Because the `Sample.direct_ancestor` field can be updated
1532+ schema_manager .delete_memcached_cache ([sample_uuid ])
15211533 except TransactionError :
15221534 # No need to log
15231535 raise
@@ -1553,6 +1565,8 @@ def link_publication_to_associated_collection(property_key, normalized_type, use
15531565 # Create a linkage
15541566 # between the Publication node and the Collection node in neo4j
15551567 schema_neo4j_queries .link_publication_to_associated_collection (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], associated_collection_uuid )
1568+
1569+ # Will need to delete the collection cache if later we add `Collection.associated_publications` field - 7/16/2023 Zhou
15561570 except TransactionError :
15571571 # No need to log
15581572 raise
@@ -1791,6 +1805,8 @@ def link_upload_to_lab(property_key, normalized_type, user_token, existing_data_
17911805 # Create a linkage (via Activity node)
17921806 # between the Submission node and the parent Lab node in neo4j
17931807 schema_neo4j_queries .link_entity_to_direct_ancestors (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], direct_ancestor_uuids , activity_data_dict )
1808+
1809+ # No need to delete any cache here since this is one-time upload creation
17941810 except TransactionError :
17951811 # No need to log
17961812 raise
@@ -1818,9 +1834,17 @@ def link_datasets_to_upload(property_key, normalized_type, user_token, existing_
18181834 if 'dataset_uuids_to_link' not in existing_data_dict :
18191835 raise KeyError ("Missing 'dataset_uuids_to_link' key in 'existing_data_dict' during calling 'link_datasets_to_upload()' trigger method." )
18201836
1837+ upload_uuid = existing_data_dict ['uuid' ]
1838+ dataset_uuids = existing_data_dict ['dataset_uuids_to_link' ]
1839+
18211840 try :
18221841 # Create a direct linkage (Dataset) - [:IN_UPLOAD] -> (Submission) for each dataset
1823- schema_neo4j_queries .link_datasets_to_upload (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], existing_data_dict ['dataset_uuids_to_link' ])
1842+ schema_neo4j_queries .link_datasets_to_upload (schema_manager .get_neo4j_driver_instance (), upload_uuid , dataset_uuids )
1843+
1844+ # Delete the cache of each associated dataset and the target upload if any cache exists
1845+ # Because the `Dataset.upload` and `Upload.datasets` fields, and
1846+ uuids_list = [upload_uuid ] + dataset_uuids
1847+ schema_manager .delete_memcached_cache (uuids_list )
18241848 except TransactionError :
18251849 # No need to log
18261850 raise
@@ -1849,9 +1873,17 @@ def unlink_datasets_from_upload(property_key, normalized_type, user_token, exist
18491873 if 'dataset_uuids_to_unlink' not in existing_data_dict :
18501874 raise KeyError ("Missing 'dataset_uuids_to_unlink' key in 'existing_data_dict' during calling 'unlink_datasets_from_upload()' trigger method." )
18511875
1876+ upload_uuid = existing_data_dict ['uuid' ]
1877+ dataset_uuids = existing_data_dict ['dataset_uuids_to_unlink' ]
1878+
18521879 try :
18531880 # Delete the linkage (Dataset) - [:IN_UPLOAD] -> (Upload) for each dataset
1854- schema_neo4j_queries .unlink_datasets_from_upload (schema_manager .get_neo4j_driver_instance (), existing_data_dict ['uuid' ], existing_data_dict ['dataset_uuids_to_unlink' ])
1881+ schema_neo4j_queries .unlink_datasets_from_upload (schema_manager .get_neo4j_driver_instance (), upload_uuid , dataset_uuids )
1882+
1883+ # Delete the cache of each associated dataset and the upload itself if any cache exists
1884+ # Because the associated datasets have this `Dataset.upload` field and Upload has `Upload.datasets` field
1885+ uuids_list = dataset_uuids + [upload_uuid ]
1886+ schema_manager .delete_memcached_cache (uuids_list )
18551887 except TransactionError :
18561888 # No need to log
18571889 raise
0 commit comments