Skip to content

Commit

Permalink
Adding cascaded delete to CppNode and CppEdge. Deleting entries for a…
Browse files Browse the repository at this point in the history
…ffected files and AST nodes.
  • Loading branch information
mcserep committed Jun 21, 2018
1 parent 560388e commit ccb943b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/cpp/model/include/model/cppedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ struct CppEdge
CppEdgeId id;

#pragma db not_null
#pragma db on_delete(cascade)
std::shared_ptr<CppNode> from;

#pragma db not_null
#pragma db on_delete(cascade)
std::shared_ptr<CppNode> to;

#pragma db not_null
Expand Down Expand Up @@ -93,6 +95,7 @@ struct CppEdgeAttribute
CppEdgeAttributeId id;

#pragma db not_null
#pragma db on_delete(cascade)
std::shared_ptr<CppEdge> edge;

#pragma db not_null
Expand Down
1 change: 1 addition & 0 deletions plugins/cpp/model/include/model/cppnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CppNodeAttribute
CppNodeAttributeId id;

#pragma db not_null
#pragma db on_delete(cascade)
std::shared_ptr<CppNode> node;

#pragma db not_null
Expand Down
18 changes: 18 additions & 0 deletions plugins/cpp/parser/src/cppparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ bool CppParser::parse()
{
_ctx.db->erase<model::CppFriendship>(friendship.id);
}

// Delete CppNode (connected to CppAstNode)
auto delNodes = _ctx.db->query<model::CppNode>(
odb::query<model::CppNode>::domainId == std::to_string(astNode.id) &&
odb::query<model::CppNode>::domain == model::CppNode::CPPASTNODE);
for(const model::CppNode& node : delNodes)
{
_ctx.db->erase<model::CppNode>(node.id);
}
}

// Delete BuildAction
Expand All @@ -445,6 +454,15 @@ bool CppParser::parse()
_ctx.db->erase<model::BuildAction>(source.action->id);
}

// Delete CppNode (connected to File)
auto delNodes = _ctx.db->query<model::CppNode>(
odb::query<model::CppNode>::domainId == std::to_string(delFile->id) &&
odb::query<model::CppNode>::domain == model::CppNode::FILE);
for(const model::CppNode& node : delNodes)
{
_ctx.db->erase<model::CppNode>(node.id);
}

// Delete File
_ctx.db->erase<model::File>(delFile->id);

Expand Down

0 comments on commit ccb943b

Please sign in to comment.