data: increased project load and codeview performance
* rewrote searchnode to use map * added local cache for parent node ids when creating the Hierarchy Cache. * added indices to SqliteStorage to increase code view performance.
This commit is contained in:
@@ -159,6 +159,8 @@ add_files(
|
||||
data/HierarchyCache.h
|
||||
data/IntermediateStorage.cpp
|
||||
data/IntermediateStorage.h
|
||||
data/SqliteIndex.cpp
|
||||
data/SqliteIndex.h
|
||||
data/SqliteStorage.cpp
|
||||
data/SqliteStorage.h
|
||||
data/Storage.cpp
|
||||
|
||||
@@ -556,8 +556,8 @@ std::shared_ptr<TokenLocationFile> CodeController::getTokenLocationOfParentScope
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
std::vector<std::string>* errorMessages)
|
||||
const {
|
||||
std::vector<std::string>* errorMessages) const
|
||||
{
|
||||
TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errorMessages);
|
||||
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "data/SqliteIndex.h"
|
||||
|
||||
SqliteIndex::SqliteIndex(const std::string& indexName, const std::string& indexTarget)
|
||||
: m_indexName(indexName)
|
||||
, m_indexTarget(indexTarget)
|
||||
{
|
||||
}
|
||||
|
||||
SqliteIndex::~SqliteIndex()
|
||||
{
|
||||
}
|
||||
|
||||
void SqliteIndex::createOnDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"CREATE INDEX IF NOT EXISTS " + m_indexName + " ON " + m_indexTarget + ";"
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteIndex::removeFromDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"DROP INDEX IF EXISTS main." + m_indexName + ";"
|
||||
).c_str());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef SQLITE_INDEX_H
|
||||
#define SQLITE_INDEX_H
|
||||
|
||||
#include <string>
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
class SqliteIndex
|
||||
{
|
||||
public:
|
||||
SqliteIndex(const std::string& indexName, const std::string& indexTarget);
|
||||
~SqliteIndex();
|
||||
|
||||
void createOnDatabase(CppSQLite3DB& database);
|
||||
void removeFromDatabase(CppSQLite3DB& database);
|
||||
|
||||
private:
|
||||
std::string m_indexName;
|
||||
std::string m_indexTarget;
|
||||
};
|
||||
|
||||
#endif // SQLITE_INDEX_H
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/SqliteIndex.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
@@ -783,6 +784,9 @@ void SqliteStorage::setupTables()
|
||||
"FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
SqliteIndex("source_location_element_id_index", "source_location(element_id)").createOnDatabase(m_database);
|
||||
SqliteIndex("source_location_file_node_id_index", "source_location(file_node_id)").createOnDatabase(m_database);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS component_access("
|
||||
"id INTEGER NOT NULL, "
|
||||
|
||||
@@ -1083,9 +1083,13 @@ void Storage::buildHierarchyCache()
|
||||
{
|
||||
std::vector<StorageEdge> memberEdges = m_sqliteStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
|
||||
Cache<Id, Node::NodeType> nodeTypeCache([this](Id id){
|
||||
return Node::intToType(m_sqliteStorage.getNodeById(id).type);
|
||||
});
|
||||
|
||||
for (const StorageEdge& edge : memberEdges)
|
||||
{
|
||||
bool isVisible = !(Node::intToType(m_sqliteStorage.getNodeById(edge.sourceNodeId).type) & Node::NODE_NOT_VISIBLE);
|
||||
bool isVisible = !(nodeTypeCache.getValue(edge.sourceNodeId) & Node::NODE_NOT_VISIBLE);
|
||||
m_hierarchyCache.createConnection(edge.id, edge.sourceNodeId, edge.targetNodeId, isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ size_t SearchNode::getNodeCount() const
|
||||
{
|
||||
size_t count = 1;
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>>& p : m_nodes)
|
||||
{
|
||||
count += n->getNodeCount();
|
||||
count += p.second->getNodeCount();
|
||||
}
|
||||
|
||||
return count;
|
||||
@@ -104,9 +104,9 @@ bool SearchNode::hasTokenIdsRecursive() const
|
||||
return true;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>>& p : m_nodes)
|
||||
{
|
||||
if (n->hasTokenIdsRecursive())
|
||||
if (p.second->hasTokenIdsRecursive())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ std::deque<SearchNode*> SearchNode::getParentsWithoutTokenId()
|
||||
return nodes;
|
||||
}
|
||||
|
||||
const std::set<std::shared_ptr<SearchNode>>& SearchNode::getChildren() const
|
||||
const std::map<Id, std::shared_ptr<SearchNode>>& SearchNode::getChildren() const
|
||||
{
|
||||
return m_nodes;
|
||||
}
|
||||
@@ -157,12 +157,12 @@ SearchResults SearchNode::runFuzzySearch(const std::string& query) const
|
||||
{
|
||||
SearchResults result;
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>>& p : m_nodes)
|
||||
{
|
||||
FuzzyMap m = n->fuzzyMatchRecursive(query, 0, 0, 0);
|
||||
for (const std::pair<size_t, const SearchNode*>& p : m)
|
||||
FuzzyMap m = p.second->fuzzyMatchRecursive(query, 0, 0, 0);
|
||||
for (const std::pair<size_t, const SearchNode*>& p2 : m)
|
||||
{
|
||||
addResultsRecursive(&result, p.first, p.second, n.get());
|
||||
addResultsRecursive(&result, p2.first, p2.second, p.second.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,9 +208,9 @@ void SearchNode::addResultsRecursive(
|
||||
) const {
|
||||
results->insert(SearchResult(weight, node, parent));
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: node->m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>>& p : node->m_nodes)
|
||||
{
|
||||
addResultsRecursive(results, weight, n.get(), parent);
|
||||
addResultsRecursive(results, weight, p.second.get(), parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ std::shared_ptr<SearchNode> SearchNode::addNodeRecursive(
|
||||
if (!node)
|
||||
{
|
||||
node = std::make_shared<SearchNode>(this, dictionary.getWord(nameId), nameId);
|
||||
m_nodes.insert(node);
|
||||
m_nodes.emplace(nameId, node);
|
||||
}
|
||||
|
||||
if (nameIds->size() > 0)
|
||||
@@ -256,13 +256,11 @@ std::shared_ptr<SearchNode> SearchNode::getNodeRecursive(std::deque<Id>* nameIds
|
||||
|
||||
void SearchNode::removeSearchNode(SearchNode* node)
|
||||
{
|
||||
for (std::set<std::shared_ptr<SearchNode>>::iterator it = m_nodes.begin(); it != m_nodes.end(); it++)
|
||||
std::map<Id, std::shared_ptr<SearchNode>>::iterator it = m_nodes.find(node->getNameId());
|
||||
|
||||
if (it != m_nodes.end())
|
||||
{
|
||||
if ((*it)->m_nameId == node->m_nameId)
|
||||
{
|
||||
m_nodes.erase(it);
|
||||
return;
|
||||
}
|
||||
m_nodes.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,9 +313,9 @@ SearchNode::FuzzyMap SearchNode::fuzzyMatchRecursive(
|
||||
return result;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<SearchNode> n: m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>>& p : m_nodes)
|
||||
{
|
||||
FuzzyMap m = n->fuzzyMatchRecursive(query, pos, weight, size + m_name.size() + SearchIndex::DELIMITER.size());
|
||||
FuzzyMap m = p.second->fuzzyMatchRecursive(query, pos, weight, size + m_name.size() + SearchIndex::DELIMITER.size());
|
||||
result.insert(m.begin(), m.end());
|
||||
}
|
||||
|
||||
@@ -413,12 +411,11 @@ std::pair<size_t, size_t> SearchNode::fuzzyMatch(
|
||||
|
||||
std::shared_ptr<SearchNode> SearchNode::getChildWithNameId(Id nameId) const
|
||||
{
|
||||
for (std::shared_ptr<SearchNode> n: m_nodes)
|
||||
std::map<Id, std::shared_ptr<SearchNode>>::const_iterator it = m_nodes.find(nameId);
|
||||
|
||||
if (it != m_nodes.end())
|
||||
{
|
||||
if (n->m_nameId == nameId)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -449,9 +446,9 @@ std::ostream& operator<<(std::ostream& ostream, const SearchNode* node)
|
||||
|
||||
ostream << '\n';
|
||||
|
||||
for (const std::shared_ptr<SearchNode> n : node->m_nodes)
|
||||
for (const std::pair<Id, std::shared_ptr<SearchNode>> p : node->m_nodes)
|
||||
{
|
||||
ostream << n.get();
|
||||
ostream << p.second.get();
|
||||
}
|
||||
|
||||
return ostream;
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
SearchNode* getParent() const;
|
||||
std::deque<SearchNode*> getParentsWithoutTokenId();
|
||||
|
||||
const std::set<std::shared_ptr<SearchNode>>& getChildren() const;
|
||||
const std::map<Id, std::shared_ptr<SearchNode>>& getChildren() const;
|
||||
|
||||
SearchResults runFuzzySearch(const std::string& query) const;
|
||||
SearchResults runFuzzySearchCached(const std::string& query, const SearchResults& searchResults) const;
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
std::shared_ptr<SearchNode> getChildWithNameId(Id nameId) const;
|
||||
std::deque<const SearchNode*> getNodesToParent(const SearchNode* parent) const;
|
||||
|
||||
std::set<std::shared_ptr<SearchNode>> m_nodes;
|
||||
std::map<Id, std::shared_ptr<SearchNode>> m_nodes;
|
||||
SearchNode* m_parent;
|
||||
|
||||
std::set<Id> m_tokenIds;
|
||||
|
||||
Reference in New Issue
Block a user