data: reducing database size by discarding indices
* added storage modes to facilitate adding and removing sqlite indices as needed.
This commit is contained in:
@@ -221,6 +221,7 @@ void Project::load()
|
|||||||
|
|
||||||
if (canLoad)
|
if (canLoad)
|
||||||
{
|
{
|
||||||
|
m_storage->setMode(SqliteStorage::STORAGE_MODE_READ);
|
||||||
m_storage->buildCaches();
|
m_storage->buildCaches();
|
||||||
m_storageAccessProxy->setSubject(m_storage.get());
|
m_storageAccessProxy->setSubject(m_storage.get());
|
||||||
|
|
||||||
@@ -324,6 +325,7 @@ bool Project::buildIndex(bool forceRefresh)
|
|||||||
fileRegister->setFilePaths(utility::toVector(filesToParse));
|
fileRegister->setFilePaths(utility::toVector(filesToParse));
|
||||||
|
|
||||||
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
|
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
|
||||||
|
m_storage.get(),
|
||||||
fileRegister,
|
fileRegister,
|
||||||
m_dialogView
|
m_dialogView
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -252,6 +252,11 @@ void PersistentStorage::finishInjection()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PersistentStorage::setMode(const SqliteStorage::StorageModeType mode)
|
||||||
|
{
|
||||||
|
m_sqliteStorage.setMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
FilePath PersistentStorage::getDbFilePath() const
|
FilePath PersistentStorage::getDbFilePath() const
|
||||||
{
|
{
|
||||||
return m_sqliteStorage.getDbFilePath();
|
return m_sqliteStorage.getDbFilePath();
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
virtual void startInjection();
|
virtual void startInjection();
|
||||||
virtual void finishInjection();
|
virtual void finishInjection();
|
||||||
|
|
||||||
|
void setMode(const SqliteStorage::StorageModeType mode);
|
||||||
|
|
||||||
FilePath getDbFilePath() const;
|
FilePath getDbFilePath() const;
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "data/location/TokenLocation.h"
|
#include "data/location/TokenLocation.h"
|
||||||
#include "data/DefinitionType.h"
|
#include "data/DefinitionType.h"
|
||||||
#include "data/parser/ParseLocation.h"
|
#include "data/parser/ParseLocation.h"
|
||||||
#include "data/SqliteIndex.h"
|
|
||||||
#include "utility/logging/logging.h"
|
#include "utility/logging/logging.h"
|
||||||
#include "utility/text/TextAccess.h"
|
#include "utility/text/TextAccess.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
@@ -19,6 +18,15 @@ SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
|
|||||||
m_database.open(m_dbFilePath.str().c_str());
|
m_database.open(m_dbFilePath.str().c_str());
|
||||||
|
|
||||||
m_database.execDML("PRAGMA foreign_keys=ON;");
|
m_database.execDML("PRAGMA foreign_keys=ON;");
|
||||||
|
|
||||||
|
m_mode = STORAGE_MODE_UNKNOWN;
|
||||||
|
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_WRITE, SqliteIndex("edge_multipart_index", "edge(type, source_node_id, target_node_id)")));
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_WRITE | STORAGE_MODE_READ | STORAGE_MODE_CLEAR, SqliteIndex("node_serialized_name_index", "node(serialized_name)")));
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_WRITE, SqliteIndex("local_symbol_name_index", "local_symbol(name)")));
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_READ | STORAGE_MODE_CLEAR, SqliteIndex("source_location_file_node_id_index", "source_location(file_node_id)")));
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_WRITE, SqliteIndex("source_location_all_data_index", "source_location(file_node_id, start_line, start_column, end_line, end_column, type)")));
|
||||||
|
m_indices.push_back(std::make_pair(STORAGE_MODE_WRITE | STORAGE_MODE_READ | STORAGE_MODE_CLEAR, SqliteIndex("component_access_node_id_index", "component_access(node_id)")));
|
||||||
}
|
}
|
||||||
|
|
||||||
SqliteStorage::~SqliteStorage()
|
SqliteStorage::~SqliteStorage()
|
||||||
@@ -37,6 +45,7 @@ void SqliteStorage::setup()
|
|||||||
{
|
{
|
||||||
m_database.execDML("PRAGMA foreign_keys=ON;");
|
m_database.execDML("PRAGMA foreign_keys=ON;");
|
||||||
setupTables();
|
setupTables();
|
||||||
|
m_mode = STORAGE_MODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqliteStorage::clear()
|
void SqliteStorage::clear()
|
||||||
@@ -47,6 +56,28 @@ void SqliteStorage::clear()
|
|||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SqliteStorage::setMode(const StorageModeType mode)
|
||||||
|
{
|
||||||
|
if (mode == m_mode)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m_indices.size(); i++)
|
||||||
|
{
|
||||||
|
if (m_indices[i].first & mode)
|
||||||
|
{
|
||||||
|
m_indices[i].second.createOnDatabase(m_database);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_indices[i].second.removeFromDatabase(m_database);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
void SqliteStorage::beginTransaction()
|
void SqliteStorage::beginTransaction()
|
||||||
{
|
{
|
||||||
m_database.execDML("BEGIN TRANSACTION;");
|
m_database.execDML("BEGIN TRANSACTION;");
|
||||||
@@ -295,7 +326,7 @@ void SqliteStorage::removeElements(const std::vector<Id>& ids)
|
|||||||
).c_str());
|
).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqliteStorage::removeElementsWithLocationInFiles(const std::vector<Id>& fileIds) // TODO: make one single clearFiles method
|
void SqliteStorage::removeElementsWithLocationInFiles(const std::vector<Id>& fileIds)
|
||||||
{
|
{
|
||||||
m_database.execDML((
|
m_database.execDML((
|
||||||
"DELETE FROM source_location WHERE file_node_id IN (" + utility::join(utility::toStrings(fileIds), ',') + ");"
|
"DELETE FROM source_location WHERE file_node_id IN (" + utility::join(utility::toStrings(fileIds), ',') + ");"
|
||||||
@@ -763,11 +794,6 @@ void SqliteStorage::setupTables()
|
|||||||
"FOREIGN KEY(target_node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
"FOREIGN KEY(target_node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: move to createIndexesForAnalysis() or prepareForAnalysis
|
|
||||||
m_database.execDML( // used for checking for duplicates during code analysis
|
|
||||||
"CREATE INDEX IF NOT EXISTS edge_multipart_index ON edge(type, source_node_id, target_node_id);"
|
|
||||||
);
|
|
||||||
|
|
||||||
m_database.execDML(
|
m_database.execDML(
|
||||||
"CREATE TABLE IF NOT EXISTS node("
|
"CREATE TABLE IF NOT EXISTS node("
|
||||||
"id INTEGER NOT NULL, "
|
"id INTEGER NOT NULL, "
|
||||||
@@ -778,10 +804,6 @@ void SqliteStorage::setupTables()
|
|||||||
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
|
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
|
||||||
);
|
);
|
||||||
|
|
||||||
m_database.execDML(
|
|
||||||
"CREATE INDEX IF NOT EXISTS node_serialized_name_index ON node(serialized_name);"
|
|
||||||
);
|
|
||||||
|
|
||||||
m_database.execDML(
|
m_database.execDML(
|
||||||
"CREATE TABLE IF NOT EXISTS file("
|
"CREATE TABLE IF NOT EXISTS file("
|
||||||
"id INTEGER NOT NULL, "
|
"id INTEGER NOT NULL, "
|
||||||
@@ -810,10 +832,6 @@ void SqliteStorage::setupTables()
|
|||||||
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
|
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
|
||||||
);
|
);
|
||||||
|
|
||||||
m_database.execDML(
|
|
||||||
"CREATE INDEX IF NOT EXISTS local_symbol_name_index ON local_symbol(name);"
|
|
||||||
);
|
|
||||||
|
|
||||||
m_database.execDML(
|
m_database.execDML(
|
||||||
"CREATE TABLE IF NOT EXISTS source_location("
|
"CREATE TABLE IF NOT EXISTS source_location("
|
||||||
"id INTEGER NOT NULL, "
|
"id INTEGER NOT NULL, "
|
||||||
@@ -827,9 +845,6 @@ void SqliteStorage::setupTables()
|
|||||||
"FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
"FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||||
);
|
);
|
||||||
|
|
||||||
SqliteIndex("source_location_file_node_id_index", "source_location(file_node_id)").createOnDatabase(m_database);
|
|
||||||
SqliteIndex("source_location_all_data_index", "source_location(file_node_id, start_line, start_column, end_line, end_column, type)").createOnDatabase(m_database);
|
|
||||||
|
|
||||||
m_database.execDML(
|
m_database.execDML(
|
||||||
"CREATE TABLE IF NOT EXISTS occurrence(" // TODO: properly delete this on refresh
|
"CREATE TABLE IF NOT EXISTS occurrence(" // TODO: properly delete this on refresh
|
||||||
"element_id INTEGER NOT NULL, "
|
"element_id INTEGER NOT NULL, "
|
||||||
@@ -848,8 +863,6 @@ void SqliteStorage::setupTables()
|
|||||||
"FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
"FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||||
);
|
);
|
||||||
|
|
||||||
SqliteIndex("component_access_node_id_index", "component_access(node_id)").createOnDatabase(m_database);
|
|
||||||
|
|
||||||
m_database.execDML(
|
m_database.execDML(
|
||||||
"CREATE TABLE IF NOT EXISTS comment_location("
|
"CREATE TABLE IF NOT EXISTS comment_location("
|
||||||
"id INTEGER NOT NULL, "
|
"id INTEGER NOT NULL, "
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "data/location/TokenLocationCollection.h"
|
#include "data/location/TokenLocationCollection.h"
|
||||||
#include "data/name/NameHierarchy.h"
|
#include "data/name/NameHierarchy.h"
|
||||||
#include "data/StorageTypes.h"
|
#include "data/StorageTypes.h"
|
||||||
|
#include "data/SqliteIndex.h"
|
||||||
|
|
||||||
class TextAccess;
|
class TextAccess;
|
||||||
class Version;
|
class Version;
|
||||||
@@ -21,12 +22,22 @@ struct ParseLocation;
|
|||||||
class SqliteStorage
|
class SqliteStorage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum StorageModeType
|
||||||
|
{
|
||||||
|
STORAGE_MODE_UNKNOWN = 0,
|
||||||
|
STORAGE_MODE_READ = 1,
|
||||||
|
STORAGE_MODE_WRITE = 2,
|
||||||
|
STORAGE_MODE_CLEAR = 4,
|
||||||
|
};
|
||||||
|
|
||||||
SqliteStorage(const FilePath& dbFilePath);
|
SqliteStorage(const FilePath& dbFilePath);
|
||||||
~SqliteStorage();
|
~SqliteStorage();
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
void setMode(const StorageModeType mode);
|
||||||
|
|
||||||
void beginTransaction();
|
void beginTransaction();
|
||||||
void commitTransaction();
|
void commitTransaction();
|
||||||
void rollbackTransaction();
|
void rollbackTransaction();
|
||||||
@@ -105,8 +116,6 @@ public:
|
|||||||
StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const;
|
StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const;
|
||||||
std::vector<StorageComponentAccess> getComponentAccessesByNodeIds(const std::vector<Id>& memberEdgeIds) const;
|
std::vector<StorageComponentAccess> getComponentAccessesByNodeIds(const std::vector<Id>& memberEdgeIds) const;
|
||||||
|
|
||||||
std::vector<ParseLocation> getFullTextSearch(const std::string& searchTerm) const;
|
|
||||||
|
|
||||||
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
|
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||||
|
|
||||||
std::vector<StorageFile> getAllFiles() const;
|
std::vector<StorageFile> getAllFiles() const;
|
||||||
@@ -158,6 +167,9 @@ private:
|
|||||||
|
|
||||||
mutable CppSQLite3DB m_database;
|
mutable CppSQLite3DB m_database;
|
||||||
FilePath m_dbFilePath;
|
FilePath m_dbFilePath;
|
||||||
|
|
||||||
|
StorageModeType m_mode;
|
||||||
|
std::vector<std::pair<int, SqliteIndex>> m_indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
|||||||
m_dialogView->showProgressDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
|
m_dialogView->showProgressDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
|
||||||
|
|
||||||
m_start = utility::durationStart();
|
m_start = utility::durationStart();
|
||||||
|
|
||||||
|
if (!m_filePaths.empty())
|
||||||
|
{
|
||||||
|
m_storage->setMode(SqliteStorage::STORAGE_MODE_CLEAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ TaskFinishParsing::~TaskFinishParsing()
|
|||||||
|
|
||||||
void TaskFinishParsing::doEnter(std::shared_ptr<Blackboard> blackboard)
|
void TaskFinishParsing::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
m_storage->setMode(SqliteStorage::STORAGE_MODE_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
#include "data/parser/TaskParseWrapper.h"
|
#include "data/parser/TaskParseWrapper.h"
|
||||||
|
|
||||||
#include "component/view/DialogView.h"
|
#include "component/view/DialogView.h"
|
||||||
|
#include "data/PersistentStorage.h"
|
||||||
#include "utility/file/FileRegister.h"
|
#include "utility/file/FileRegister.h"
|
||||||
#include "utility/scheduling/Blackboard.h"
|
#include "utility/scheduling/Blackboard.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
|
|
||||||
TaskParseWrapper::TaskParseWrapper(
|
TaskParseWrapper::TaskParseWrapper(
|
||||||
|
PersistentStorage* storage,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
)
|
)
|
||||||
: m_fileRegister(fileRegister)
|
: m_storage(storage)
|
||||||
|
, m_fileRegister(fileRegister)
|
||||||
, m_dialogView(dialogView)
|
, m_dialogView(dialogView)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -29,9 +32,16 @@ void TaskParseWrapper::setTask(std::shared_ptr<Task> task)
|
|||||||
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
blackboard->set("indexer_count", 0);
|
blackboard->set("indexer_count", 0);
|
||||||
m_dialogView->updateIndexingDialog(0, m_fileRegister->getSourceFilesCount(), "");
|
|
||||||
|
const size_t sourceFileCount = m_fileRegister->getSourceFilesCount();
|
||||||
|
m_dialogView->updateIndexingDialog(0, sourceFileCount, "");
|
||||||
|
|
||||||
m_start = utility::durationStart();
|
m_start = utility::durationStart();
|
||||||
|
|
||||||
|
if (sourceFileCount > 0)
|
||||||
|
{
|
||||||
|
m_storage->setMode(SqliteStorage::STORAGE_MODE_WRITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
|
|||||||
@@ -12,12 +12,14 @@
|
|||||||
|
|
||||||
class DialogView;
|
class DialogView;
|
||||||
class FileRegister;
|
class FileRegister;
|
||||||
|
class PersistentStorage;
|
||||||
|
|
||||||
class TaskParseWrapper
|
class TaskParseWrapper
|
||||||
: public TaskDecorator
|
: public TaskDecorator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TaskParseWrapper(
|
TaskParseWrapper(
|
||||||
|
PersistentStorage* storage,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
);
|
);
|
||||||
@@ -31,6 +33,7 @@ private:
|
|||||||
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
|
PersistentStorage* m_storage;
|
||||||
std::shared_ptr<FileRegister> m_fileRegister;
|
std::shared_ptr<FileRegister> m_fileRegister;
|
||||||
DialogView* m_dialogView;
|
DialogView* m_dialogView;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user