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:
Eberhard Graether
2015-10-05 09:44:27 +02:00
parent f041e69789
commit 8d3112d5a9
7 changed files with 43 additions and 47 deletions
+3 -3
View File
@@ -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));
+7 -7
View File
@@ -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(
+1 -1
View File
@@ -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;
+10 -7
View File
@@ -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);
}
}
+1 -1
View File
@@ -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;
+18 -24
View File
@@ -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()
+3 -4
View File
@@ -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;