logic: improved performance of storing index to database

* add compiled statement for batch inserting 100 occurrences at once
* removed unnecessary primary key from component_access to get rid of additional index table
* changed explicit check for existing symbols when injecting to implicit check in insert statement (insert or ignore)
* improved performance of adding edges by replacing edge multi part index with in-memory-index
* added in-memory-index for node table
* added in-memory-index for local_symbol table
* added in-memory-index for lource_location table
* moved setting storage mode to SqliteIndexStorage, because storage modes are not used anywhere else.
* don't store current mode as member because re-creating an existing index takes no time.
* add getter for name of SqliteDatabaseIndex
* removed unused method from persistent storage
This commit is contained in:
mlangkabel
2018-08-10 15:37:08 +02:00
parent 52d0236f9a
commit 337cf2d371
22 changed files with 262 additions and 265 deletions
+7 -42
View File
@@ -48,28 +48,12 @@ PersistentStorage::PersistentStorage(const FilePath& dbPath, const FilePath& boo
Id PersistentStorage::addNode(const StorageNodeData& data)
{
const StorageNode storedNode = m_sqliteIndexStorage.getNodeBySerializedName(data.serializedName);
if (storedNode.id == 0)
{
return m_sqliteIndexStorage.addNode(data).id;
}
if (storedNode.type < data.type)
{
m_sqliteIndexStorage.setNodeType(data.type, storedNode.id);
return storedNode.id;
}
return storedNode.id;
return m_sqliteIndexStorage.addNode(data).id;
}
void PersistentStorage::addSymbol(const StorageSymbol& data)
{
if (m_sqliteIndexStorage.getFirstById<StorageSymbol>(data.id).id == 0)
{
m_sqliteIndexStorage.addSymbol(data);
}
m_sqliteIndexStorage.addSymbol(data);
}
void PersistentStorage::addFile(const StorageFile& data)
@@ -96,22 +80,12 @@ void PersistentStorage::addFile(const StorageFile& data)
Id PersistentStorage::addEdge(const StorageEdgeData& data)
{
const StorageEdge storedEdge = m_sqliteIndexStorage.getEdgeBySourceTargetType(data.sourceNodeId, data.targetNodeId, data.type);
if (storedEdge.id == 0)
{
return m_sqliteIndexStorage.addEdge(data).id;
}
return storedEdge.id;
return m_sqliteIndexStorage.addEdge(data).id;
}
Id PersistentStorage::addLocalSymbol(const StorageLocalSymbolData& data)
{
const StorageLocalSymbol storedLocalSymbol = m_sqliteIndexStorage.getLocalSymbolByName(data.name);
if (storedLocalSymbol.id == 0)
{
return m_sqliteIndexStorage.addLocalSymbol(data).id;
}
return storedLocalSymbol.id;
return m_sqliteIndexStorage.addLocalSymbol(data).id;
}
Id PersistentStorage::addSourceLocation(const StorageSourceLocationData& data)
@@ -129,9 +103,9 @@ void PersistentStorage::addOccurrences(const std::vector<StorageOccurrence>& occ
m_sqliteIndexStorage.addOccurrences(occurrences);
}
void PersistentStorage::addComponentAccess(const StorageComponentAccessData& data)
void PersistentStorage::addComponentAccess(const StorageComponentAccess& componentAccess)
{
m_sqliteIndexStorage.addComponentAccess(data);
m_sqliteIndexStorage.addComponentAccess(componentAccess);
}
void PersistentStorage::addCommentLocation(const StorageCommentLocationData& data)
@@ -200,7 +174,7 @@ void PersistentStorage::forEachOccurrence(std::function<void(const StorageOccurr
}
}
void PersistentStorage::forEachComponentAccess(std::function<void(const StorageComponentAccessData& /*data*/)> callback) const
void PersistentStorage::forEachComponentAccess(std::function<void(const StorageComponentAccess& /*data*/)> callback) const
{
for (StorageComponentAccess& componentAccess: m_sqliteIndexStorage.getAll<StorageComponentAccess>())
{
@@ -540,15 +514,6 @@ NodeType PersistentStorage::getNodeTypeForNodeWithId(Id nodeId) const
return NodeType::intToType(m_sqliteIndexStorage.getFirstById<StorageNode>(nodeId).type);
}
Id PersistentStorage::getIdForEdge(
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy
) const
{
const Id sourceId = getNodeIdForNameHierarchy(fromNameHierarchy);
const Id targetId = getNodeIdForNameHierarchy(toNameHierarchy);
return m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
}
StorageEdge PersistentStorage::getEdgeById(Id edgeId) const
{
return m_sqliteIndexStorage.getEdgeById(edgeId);