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):
log.info("Deleting {0} nodes.".format(node_type))
subgraph = graph.nodes.match(node_type)
deleted_nodes = len(subgraph)
for node in subgraph:
graph.delete(node)
# this is the recommended way to delete a number of nodes, rather than deleting them one by one
query = "MATCH (node:{0}) DETACH DELETE node RETURN count(node) as count;".format(node_type)
log.info("Executing query {0}".format(query))
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):
......@@ -338,11 +339,11 @@ def delete_temporal_subgraph(graph, subgraph_id):
log.info("Deleting subgraph associated with ID {0}".format(subgraph_id))
subgraph = graph.nodes.match(uuid=subgraph_id)
nodes_matched = 0
for node in subgraph:
graph.delete(node)
nodes_matched += 1
# this is the recommended way to delete a number of nodes, rather than deleting them one by one
query = "MATCH (node {{uuid: '{0}'}}) DETACH DELETE node RETURN count(node) as count;".format(subgraph_id)
log.info("Executing query {0}".format(query))
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} 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.
Finish editing this message first!
Please register or to comment