Skip to content
Snippets Groups Projects
Commit b42bc7bf authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Updates the utility functions used to delete a subgraph

parent 7064db83
No related branches found
No related tags found
No related merge requests found
...@@ -223,14 +223,15 @@ def delete_nodes_with_type(graph, node_type): ...@@ -223,14 +223,15 @@ def delete_nodes_with_type(graph, node_type):
log.info("Deleting {0} nodes.".format(node_type)) log.info("Deleting {0} nodes.".format(node_type))
subgraph = graph.nodes.match(node_type) # this is the recommended way to delete a number of nodes, rather than deleting them one by one
deleted_nodes = len(subgraph) query = "MATCH (node:{0}) DETACH DELETE node RETURN count(node) as count;".format(node_type)
for node in subgraph: log.info("Executing query {0}".format(query))
graph.delete(node) result = graph.run(query)
nodes_matched = result.data()[0]["count"] # we expect exactly one result, which is a dictionary with key 'count'
log.info("Deleted {0} {1} nodes.".format(deleted_nodes, node_type)) log.info("Deleted {0} {1} nodes.".format(nodes_matched, node_type))
return deleted_nodes return nodes_matched
def build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queries, graph, influx_client): def build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queries, graph, influx_client):
...@@ -338,11 +339,11 @@ def delete_temporal_subgraph(graph, subgraph_id): ...@@ -338,11 +339,11 @@ def delete_temporal_subgraph(graph, subgraph_id):
log.info("Deleting subgraph associated with ID {0}".format(subgraph_id)) log.info("Deleting subgraph associated with ID {0}".format(subgraph_id))
subgraph = graph.nodes.match(uuid=subgraph_id) # this is the recommended way to delete a number of nodes, rather than deleting them one by one
nodes_matched = 0 query = "MATCH (node {{uuid: '{0}'}}) DETACH DELETE node RETURN count(node) as count;".format(subgraph_id)
for node in subgraph: log.info("Executing query {0}".format(query))
graph.delete(node) result = graph.run(query)
nodes_matched += 1 nodes_matched = result.data()[0]["count"] # we expect exactly one result, which is a dictionary with key 'count'
log.info("Deleted {0} nodes associated with ID {1}".format(nodes_matched, subgraph_id)) log.info("Deleted {0} nodes associated with ID {1}".format(nodes_matched, subgraph_id))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment