Skip to content

Commit

Permalink
clean graph with cleaning data folder (#4215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaner committed Apr 9, 2024
1 parent 203dd2f commit e5b57a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .changelog/4215.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where the graph was not fully cleaned before import in **graph update**
type: fix
pr_number: 4215
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from demisto_sdk.commands.content_graph.interface.neo4j.queries.relationships import (
_match_relationships,
create_relationships,
delete_all_graph_relationships,
get_sources_by_path,
get_targets_by_path,
)
Expand Down Expand Up @@ -663,6 +664,7 @@ def export_graph(

def clean_graph(self):
with self.driver.session() as session:
session.execute_write(delete_all_graph_relationships)
session.execute_write(delete_all_graph_nodes)
self._id_to_obj = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ def get_list_properties(tx: Transaction) -> List[str]:


def delete_all_graph_nodes(tx: Transaction) -> None:
query = """// Deletes all graph nodes and relationships
MATCH (n)
DETACH DELETE n"""
query = """// Deletes all graph nodes
MATCH (n)
CALL { WITH n
DETACH DELETE n
};
"""
run_query(tx, query)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,13 @@ def get_targets_by_path(
minDepth
ORDER BY content_type, object_id"""
return run_query(tx, query).data()


def delete_all_graph_relationships(tx: Transaction) -> None:
query = """// Deletes all graph relationships
MATCH ()-[r]->()
CALL { WITH r
DELETE r
};
"""
run_query(tx, query)

0 comments on commit e5b57a6

Please sign in to comment.