data: increased file clearing performance
This change passes all file node ids for clearing to the sqlite storage at once and makes use of ON DELETE CASCADE for everything else, instead of manally deleting all source locations.
This commit is contained in:
+3
-3
@@ -105,9 +105,9 @@ void Project::parseCode()
|
||||
|
||||
std::shared_ptr<TaskGroupSequential> taskGroup = std::make_shared<TaskGroupSequential>();
|
||||
|
||||
std::set<FilePath> filesToClean;
|
||||
utility::append(filesToClean, removedFilePaths);
|
||||
utility::append(filesToClean, updatedFilePaths);
|
||||
std::vector<FilePath> filesToClean;
|
||||
filesToClean.insert(filesToClean.end(), removedFilePaths.begin(), removedFilePaths.end());
|
||||
filesToClean.insert(filesToClean.end(), updatedFilePaths.begin(), updatedFilePaths.end());
|
||||
|
||||
taskGroup->addTask(std::make_shared<TaskCleanStorage>(m_storage.get(), filesToClean));
|
||||
|
||||
|
||||
@@ -160,13 +160,6 @@ void SqliteStorage::removeNameHierarchyElement(Id id)
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteStorage::removeElementsWithLocationInFile(Id fileId)
|
||||
{
|
||||
m_database.execDML((
|
||||
"DELETE FROM element WHERE id IN (SELECT element_id FROM source_location WHERE source_location.file_node_id == " + std::to_string(fileId) + ");"
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteStorage::removeFile(Id id)
|
||||
{
|
||||
if (isFile(id))
|
||||
@@ -181,6 +174,13 @@ void SqliteStorage::removeFile(Id id)
|
||||
}
|
||||
}
|
||||
|
||||
void SqliteStorage::removeFiles(const std::vector<Id>& fileIds)
|
||||
{
|
||||
m_database.execDML((
|
||||
"DELETE FROM element WHERE id IN (" + utility::join(utility::toStrings(fileIds), ',') + ");"
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteStorage::removeUnusedNameHierarchyElements()
|
||||
{
|
||||
m_database.execDML(
|
||||
|
||||
@@ -40,8 +40,8 @@ public:
|
||||
|
||||
void removeElement(Id id);
|
||||
void removeNameHierarchyElement(Id id);
|
||||
void removeElementsWithLocationInFile(Id fileId);
|
||||
void removeFile(Id id);
|
||||
void removeFiles(const std::vector<Id>& fileIds);
|
||||
void removeUnusedNameHierarchyElements();
|
||||
|
||||
StorageNode getFirstNode() const;
|
||||
|
||||
@@ -76,15 +76,18 @@ std::set<FilePath> Storage::getDependingFilePaths(const FilePath& filePath)
|
||||
return dependingFilePaths;
|
||||
}
|
||||
|
||||
void Storage::clearFileElement(const FilePath& filePath)
|
||||
void Storage::clearFileElements(const std::vector<FilePath>& filePaths)
|
||||
{
|
||||
Id fileId = getFileNodeId(filePath);
|
||||
if (fileId != 0)
|
||||
std::vector<Id> fileNodeIds;
|
||||
|
||||
for (const FilePath& path : filePaths)
|
||||
{
|
||||
m_sqliteStorage.beginTransaction();
|
||||
m_sqliteStorage.removeElementsWithLocationInFile(fileId);
|
||||
m_sqliteStorage.removeFile(fileId);
|
||||
m_sqliteStorage.commitTransaction();
|
||||
fileNodeIds.push_back(getFileNodeId(path));
|
||||
}
|
||||
|
||||
if (fileNodeIds.size())
|
||||
{
|
||||
m_sqliteStorage.removeFiles(fileNodeIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
std::set<FilePath> getDependingFilePaths(const std::set<FilePath>& filePaths);
|
||||
std::set<FilePath> getDependingFilePaths(const FilePath& filePath);
|
||||
|
||||
void clearFileElement(const FilePath& filePath);
|
||||
void clearFileElements(const std::vector<FilePath>& filePaths);
|
||||
void removeUnusedNames();
|
||||
|
||||
std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
|
||||
@@ -3,14 +3,11 @@
|
||||
#include "data/Storage.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
|
||||
TaskCleanStorage::TaskCleanStorage(Storage* storage, const std::set<FilePath>& filePaths)
|
||||
TaskCleanStorage::TaskCleanStorage(Storage* storage, const std::vector<FilePath>& filePaths)
|
||||
: m_storage(storage)
|
||||
, m_filePaths(filePaths)
|
||||
, m_fileCount(filePaths.size())
|
||||
{
|
||||
for (const FilePath& p : filePaths)
|
||||
{
|
||||
m_filePaths.push(p);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskCleanStorage::enter()
|
||||
@@ -20,30 +17,26 @@ void TaskCleanStorage::enter()
|
||||
|
||||
Task::TaskState TaskCleanStorage::update()
|
||||
{
|
||||
if (!m_filePaths.size())
|
||||
if (m_filePaths.size())
|
||||
{
|
||||
if (m_fileCount)
|
||||
{
|
||||
MessageStatus("Cleaning up names", false, true).dispatch();
|
||||
m_storage->removeUnusedNames();
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << "clearing " << m_filePaths.size() << " files (ESC to quit)";
|
||||
MessageStatus(ss.str(), false, true).dispatch();
|
||||
|
||||
return Task::STATE_FINISHED;
|
||||
m_storage->clearFileElements(m_filePaths);
|
||||
|
||||
m_filePaths.clear();
|
||||
|
||||
return Task::STATE_RUNNING;
|
||||
}
|
||||
|
||||
FilePath filePath = m_filePaths.front();
|
||||
m_filePaths.pop();
|
||||
if (m_fileCount)
|
||||
{
|
||||
MessageStatus("Cleaning up names (ESC to quit)", false, true).dispatch();
|
||||
m_storage->removeUnusedNames();
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "clearing (ESC to quit): [";
|
||||
ss << m_fileCount - m_filePaths.size() - 1 << "/" << m_fileCount << "] ";
|
||||
ss << filePath.str();
|
||||
|
||||
MessageStatus(ss.str(), false, true).dispatch();
|
||||
|
||||
m_storage->clearFileElement(filePath);
|
||||
|
||||
return Task::STATE_RUNNING;
|
||||
return Task::STATE_FINISHED;
|
||||
}
|
||||
|
||||
void TaskCleanStorage::exit()
|
||||
@@ -52,6 +45,7 @@ void TaskCleanStorage::exit()
|
||||
ss << "clearing files done, ";
|
||||
ss << std::setprecision(2) << std::fixed << utility::duration(m_start) << " seconds";
|
||||
MessageStatus(ss.str()).dispatch();
|
||||
|
||||
}
|
||||
|
||||
void TaskCleanStorage::interrupt()
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#ifndef TASK_CLEAN_STORAGE_H
|
||||
#define TASK_CLEAN_STORAGE_H
|
||||
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
@@ -16,7 +15,7 @@ class TaskCleanStorage
|
||||
public:
|
||||
TaskCleanStorage(
|
||||
Storage* storage,
|
||||
const std::set<FilePath>& filePaths
|
||||
const std::vector<FilePath>& filePaths
|
||||
);
|
||||
|
||||
virtual void enter();
|
||||
@@ -28,7 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
Storage* m_storage;
|
||||
std::queue<FilePath> m_filePaths;
|
||||
std::vector<FilePath> m_filePaths;
|
||||
const size_t m_fileCount;
|
||||
|
||||
utility::TimePoint m_start;
|
||||
|
||||
Reference in New Issue
Block a user