perf: PersistentStorage::getGraphForAll - avoiding second sqlite call. (#890)
* perf: PersistentStorage::getGraphForAll - avoiding second sqlite call. * std::map -> std::unordered_map for m_symbolDefinitionKinds. * src: Added PersistentStorage::addFileNodeToGraph. * src: Refactor and Bugfixes in new implementation of getGraphForAll. * std::map -> std::unordered_map for m_fileNodeIndexed. * Added PersistentStorage::addNodeToGraph.
This commit is contained in:
@@ -1024,35 +1024,36 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
|
||||
m_sqliteIndexStorage.forEach<StorageNode>([&](StorageNode&& node) {
|
||||
bool showNode = true;
|
||||
if (m_symbolDefinitionKinds.size())
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
const size_t sdk_size = m_symbolDefinitionKinds.size();
|
||||
m_sqliteIndexStorage.forEach<StorageNode>([&, sdk_size](StorageNode&& storageNode) {
|
||||
const NodeType type(NodeType::intToType(storageNode.type));
|
||||
if (type.isFile())
|
||||
{
|
||||
auto it = m_symbolDefinitionKinds.find(node.id);
|
||||
showNode = (it != m_symbolDefinitionKinds.end() && it->second == DEFINITION_EXPLICIT);
|
||||
auto fn_it = m_fileNodeIndexed.find(storageNode.id);
|
||||
if (fn_it != m_fileNodeIndexed.end() && fn_it->second)
|
||||
{
|
||||
addFileNodeToGraph(storageNode, graph.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (showNode &&
|
||||
(NodeType(NodeType::intToType(node.type)).isPackage() ||
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id)))
|
||||
else
|
||||
{
|
||||
tokenIds.push_back(node.id);
|
||||
bool showNode = true;
|
||||
if (sdk_size)
|
||||
{
|
||||
auto it = m_symbolDefinitionKinds.find(storageNode.id);
|
||||
showNode = (it != m_symbolDefinitionKinds.end() && it->second == DEFINITION_EXPLICIT);
|
||||
}
|
||||
if (showNode && (
|
||||
type.isPackage() ||
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(storageNode.id)
|
||||
)
|
||||
)
|
||||
{
|
||||
addNodeToGraph(storageNode, type, graph.get(), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const auto& p: m_fileNodeIndexed)
|
||||
{
|
||||
if (p.second)
|
||||
{
|
||||
tokenIds.push_back(p.first);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
addNodesToGraph(tokenIds, graph.get(), false);
|
||||
|
||||
return graph;
|
||||
}
|
||||
|
||||
@@ -2843,42 +2844,52 @@ void PersistentStorage::addNodesToGraph(
|
||||
|
||||
for (const StorageNode& storageNode: m_sqliteIndexStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageNode.serializedName);
|
||||
|
||||
const NodeType type(NodeType::intToType(storageNode.type));
|
||||
if (type.isFile())
|
||||
{
|
||||
const FilePath filePath(nameHierarchy.getRawName());
|
||||
|
||||
bool complete = getFileNodeComplete(storageNode.id);
|
||||
bool indexed = getFileNodeIndexed(storageNode.id);
|
||||
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
type,
|
||||
NameHierarchy(filePath.fileName(), NAME_DELIMITER_FILE),
|
||||
indexed ? DEFINITION_EXPLICIT : DEFINITION_NONE);
|
||||
node->addComponent(std::make_shared<TokenComponentFilePath>(filePath, complete));
|
||||
addFileNodeToGraph(storageNode, graph);
|
||||
}
|
||||
else
|
||||
{
|
||||
DefinitionKind defKind = DEFINITION_NONE;
|
||||
auto it = m_symbolDefinitionKinds.find(storageNode.id);
|
||||
if (it != m_symbolDefinitionKinds.end())
|
||||
{
|
||||
defKind = it->second;
|
||||
}
|
||||
|
||||
Node* node = graph->createNode(storageNode.id, type, std::move(nameHierarchy), defKind);
|
||||
|
||||
if (addChildCount)
|
||||
{
|
||||
node->setChildCount(m_hierarchyCache.getFirstChildIdsCountForNodeId(storageNode.id));
|
||||
}
|
||||
addNodeToGraph(storageNode, type, graph, addChildCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addFileNodeToGraph(const StorageNode& storageNode, Graph* const graph) const
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(storageNode.serializedName);
|
||||
const FilePath filePath(nameHierarchy.getRawName());
|
||||
|
||||
bool complete = getFileNodeComplete(storageNode.id);
|
||||
bool indexed = getFileNodeIndexed(storageNode.id);
|
||||
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
NodeType::NODE_FILE,
|
||||
NameHierarchy(filePath.fileName(), NAME_DELIMITER_FILE),
|
||||
indexed ? DEFINITION_EXPLICIT : DEFINITION_NONE);
|
||||
node->addComponent(std::make_shared<TokenComponentFilePath>(filePath, complete));
|
||||
}
|
||||
|
||||
void PersistentStorage::addNodeToGraph(const StorageNode& newNode, const NodeType& type, Graph* graph, bool addChildCount) const
|
||||
{
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(newNode.serializedName);
|
||||
DefinitionKind defKind = DEFINITION_NONE;
|
||||
auto it = m_symbolDefinitionKinds.find(newNode.id);
|
||||
if (it != m_symbolDefinitionKinds.end())
|
||||
{
|
||||
defKind = it->second;
|
||||
}
|
||||
|
||||
Node* node = graph->createNode(newNode.id, type, std::move(nameHierarchy), defKind);
|
||||
|
||||
if (addChildCount)
|
||||
{
|
||||
node->setChildCount(m_hierarchyCache.getFirstChildIdsCountForNodeId(newNode.id));
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addEdgesToGraph(const std::vector<Id>& newEdgeIds, Graph* graph) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
@@ -241,7 +241,8 @@ private:
|
||||
const std::vector<Id>& edgeIds,
|
||||
Graph* graphh,
|
||||
bool addChildCount) const;
|
||||
|
||||
inline void addFileNodeToGraph(const StorageNode& storageNode, Graph* const graph) const;
|
||||
void addNodeToGraph(const StorageNode& newNode, const NodeType& type, Graph* graph, bool addChildCount) const;
|
||||
void addAggregationEdgesToGraph(
|
||||
Id nodeId, const std::vector<StorageEdge>& edgesToAggregate, Graph* graph) const;
|
||||
void addFileContentsToGraph(Id fileId, Graph* graph) const;
|
||||
@@ -276,10 +277,10 @@ private:
|
||||
std::map<FilePath, Id> m_lowerCasefileNodeIds;
|
||||
std::map<Id, FilePath> m_fileNodePaths;
|
||||
std::map<Id, bool> m_fileNodeComplete;
|
||||
std::map<Id, bool> m_fileNodeIndexed;
|
||||
std::unordered_map<Id, bool> m_fileNodeIndexed;
|
||||
std::map<Id, std::wstring> m_fileNodeLanguage;
|
||||
|
||||
std::map<Id, DefinitionKind> m_symbolDefinitionKinds;
|
||||
std::unordered_map<Id, DefinitionKind> m_symbolDefinitionKinds;
|
||||
std::map<Id, Id> m_memberEdgeIdOrderMap;
|
||||
|
||||
HierarchyCache m_hierarchyCache;
|
||||
|
||||
Reference in New Issue
Block a user