data: refactored file clearing on reparse to use TaskClearStorage
This commit is contained in:
+40
-52
@@ -46,24 +46,6 @@ void Storage::clearCaches()
|
||||
m_hierarchyCache.clear();
|
||||
}
|
||||
|
||||
void Storage::clearFileElements(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
for (const FilePath& filePath: filePaths)
|
||||
{
|
||||
clearFileElements(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::clearFileElements(const FilePath& filePath)
|
||||
{
|
||||
Id fileId = m_sqliteStorage.getFileByName(filePath.fileName()).id;
|
||||
if (fileId != 0)
|
||||
{
|
||||
m_sqliteStorage.removeElementsWithLocationInFile(fileId);
|
||||
m_sqliteStorage.removeFile(fileId);
|
||||
}
|
||||
}
|
||||
|
||||
std::set<FilePath> Storage::getDependingFilePaths(const std::set<FilePath>& filePaths)
|
||||
{
|
||||
std::set<FilePath> dependingFilePaths;
|
||||
@@ -79,15 +61,12 @@ std::set<FilePath> Storage::getDependingFilePaths(const FilePath& filePath)
|
||||
{
|
||||
std::set<FilePath> dependingFilePaths;
|
||||
|
||||
Id fileNodeId = getFileNodeId(filePath);
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteStorage.getEdgesByTargetType(
|
||||
fileNodeId, Edge::typeToInt(Edge::EDGE_INCLUDE)
|
||||
getFileNodeId(filePath), Edge::typeToInt(Edge::EDGE_INCLUDE)
|
||||
);
|
||||
for (StorageEdge incomingEdge: incomingEdges)
|
||||
for (const StorageEdge& incomingEdge: incomingEdges)
|
||||
{
|
||||
Id dependingFileId = incomingEdge.sourceNodeId;
|
||||
FilePath dependingFilePath = FilePath(m_sqliteStorage.getFileById(dependingFileId).filePath);
|
||||
|
||||
FilePath dependingFilePath = getFileNodePath(incomingEdge.sourceNodeId);
|
||||
dependingFilePaths.insert(dependingFilePath);
|
||||
|
||||
std::set<FilePath> dependingFilePathsSubset = getDependingFilePaths(dependingFilePath);
|
||||
@@ -97,6 +76,16 @@ std::set<FilePath> Storage::getDependingFilePaths(const FilePath& filePath)
|
||||
return dependingFilePaths;
|
||||
}
|
||||
|
||||
void Storage::clearFileElement(const FilePath& filePath)
|
||||
{
|
||||
Id fileId = getFileNodeId(filePath);
|
||||
if (fileId != 0)
|
||||
{
|
||||
m_sqliteStorage.removeElementsWithLocationInFile(fileId);
|
||||
m_sqliteStorage.removeFile(fileId);
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::removeUnusedNames()
|
||||
{
|
||||
m_sqliteStorage.removeUnusedNameHierarchyElements();
|
||||
@@ -688,44 +677,30 @@ Id Storage::onMacroExpandParsed(const ParseLocation &location, const NameHierarc
|
||||
return edgeId;
|
||||
}
|
||||
|
||||
Id Storage::getIdForNodeWithName(const std::string& fullName) const // use name hierarchy here
|
||||
Id Storage::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const
|
||||
{
|
||||
std::vector<std::string> nameParts = utility::splitToVector(fullName, "::");
|
||||
Id currentId = 0;
|
||||
|
||||
Id parentId = 0;
|
||||
for (size_t i = 0; i < nameParts.size(); i++)
|
||||
for (size_t i = 0; i < nameHierarchy.size(); i++)
|
||||
{
|
||||
Id currentId = 0;
|
||||
if (parentId == 0)
|
||||
{
|
||||
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameParts[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameParts[i], parentId);
|
||||
}
|
||||
|
||||
parentId = currentId;
|
||||
Id parentId = currentId;
|
||||
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentId);
|
||||
|
||||
if (currentId == 0)
|
||||
{
|
||||
currentId = parentId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return m_sqliteStorage.getNodeByNameId(parentId).id;
|
||||
return m_sqliteStorage.getNodeByNameId(currentId).id;
|
||||
}
|
||||
|
||||
Id Storage::getIdForEdgeWithName(const std::string& name) const
|
||||
{
|
||||
Edge::EdgeType type;
|
||||
std::string sourceName;
|
||||
std::string targetName;
|
||||
|
||||
Edge::splitName(name, &type, &sourceName, &targetName);
|
||||
|
||||
int sourceId = getIdForNodeWithName(sourceName);
|
||||
int targetId = getIdForNodeWithName(targetName);
|
||||
Id Storage::getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy
|
||||
) const {
|
||||
int sourceId = getIdForNodeWithNameHierarchy(fromNameHierarchy);
|
||||
int targetId = getIdForNodeWithNameHierarchy(toNameHierarchy);
|
||||
return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
}
|
||||
|
||||
@@ -750,10 +725,10 @@ std::vector<FileInfo> Storage::getInfoOnAllFiles() const
|
||||
return fileInfos;
|
||||
}
|
||||
|
||||
std::string Storage::getNameForNodeWithId(Id nodeId) const
|
||||
NameHierarchy Storage::getNameHierarchyForNodeWithId(Id nodeId) const
|
||||
{
|
||||
Id nameHierarchyElementId = m_sqliteStorage.getNameHierarchyElementIdByNodeId(nodeId);
|
||||
return m_sqliteStorage.getNameHierarchyById(nameHierarchyElementId).getFullName();
|
||||
return m_sqliteStorage.getNameHierarchyById(nameHierarchyElementId);
|
||||
// return m_tokenIndex.getNameHierarchyForTokenId(nodeId).getFullName();
|
||||
}
|
||||
|
||||
@@ -1325,6 +1300,19 @@ Id Storage::getFileNodeId(const FilePath& filePath) const
|
||||
return storageFile.id;
|
||||
}
|
||||
|
||||
FilePath Storage::getFileNodePath(Id fileId) const
|
||||
{
|
||||
for (const std::pair<FilePath, Id>& p : m_fileNodeIds)
|
||||
{
|
||||
if (p.second == fileId)
|
||||
{
|
||||
return p.first;
|
||||
}
|
||||
}
|
||||
|
||||
return m_sqliteStorage.getFileById(fileId).filePath;
|
||||
}
|
||||
|
||||
Id Storage::getLastVisibleParentNodeId(const Id nodeId) const
|
||||
{
|
||||
return m_hierarchyCache.getLastVisibleParentNodeId(nodeId);
|
||||
|
||||
@@ -26,11 +26,10 @@ public:
|
||||
void clear();
|
||||
void clearCaches();
|
||||
|
||||
void clearFileElements(const std::set<FilePath>& filePaths);
|
||||
void clearFileElements(const FilePath& filePath);
|
||||
std::set<FilePath> getDependingFilePaths(const std::set<FilePath>& filePaths);
|
||||
std::set<FilePath> getDependingFilePaths(const FilePath& filePath);
|
||||
|
||||
void clearFileElement(const FilePath& filePath);
|
||||
void removeUnusedNames();
|
||||
|
||||
void logGraph() const;
|
||||
@@ -123,12 +122,13 @@ public:
|
||||
virtual Id onMacroExpandParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy);
|
||||
|
||||
// StorageAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& fullName) const;
|
||||
virtual Id getIdForEdgeWithName(const std::string& name) const;
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
|
||||
virtual std::string getNameForNodeWithId(Id nodeId) const;
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(
|
||||
const std::string& query, const std::string& word) const;
|
||||
@@ -168,6 +168,7 @@ private:
|
||||
Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, ParseLocation location);
|
||||
|
||||
Id getFileNodeId(const FilePath& filePath) const;
|
||||
FilePath getFileNodePath(Id fileId) const;
|
||||
|
||||
Id getLastVisibleParentNodeId(const Id nodeId) const;
|
||||
std::vector<Id> getAllChildNodeIds(const Id nodeId) const;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "data/TaskCleanStorage.h"
|
||||
|
||||
#include "data/Storage.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
|
||||
TaskCleanStorage::TaskCleanStorage(Storage* storage, const std::set<FilePath>& filePaths)
|
||||
: m_storage(storage)
|
||||
, m_fileCount(filePaths.size())
|
||||
{
|
||||
for (const FilePath& p : filePaths)
|
||||
{
|
||||
m_filePaths.push(p);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskCleanStorage::enter()
|
||||
{
|
||||
m_start = utility::durationStart();
|
||||
}
|
||||
|
||||
Task::TaskState TaskCleanStorage::update()
|
||||
{
|
||||
if (!m_filePaths.size())
|
||||
{
|
||||
if (m_fileCount)
|
||||
{
|
||||
MessageStatus("Cleaning up names", false, true).dispatch();
|
||||
m_storage->removeUnusedNames();
|
||||
}
|
||||
|
||||
return Task::STATE_FINISHED;
|
||||
}
|
||||
|
||||
FilePath filePath = m_filePaths.front();
|
||||
m_filePaths.pop();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TaskCleanStorage::exit()
|
||||
{
|
||||
// std::cout << "clean duration: " << utility::duration(m_start) << std::endl;
|
||||
}
|
||||
|
||||
void TaskCleanStorage::interrupt()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskCleanStorage::revert()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef TASK_CLEAN_STORAGE_H
|
||||
#define TASK_CLEAN_STORAGE_H
|
||||
|
||||
#include <queue>
|
||||
#include <set>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
class Storage;
|
||||
|
||||
class TaskCleanStorage
|
||||
: public Task
|
||||
{
|
||||
public:
|
||||
TaskCleanStorage(
|
||||
Storage* storage,
|
||||
const std::set<FilePath>& filePaths
|
||||
);
|
||||
|
||||
virtual void enter();
|
||||
virtual TaskState update();
|
||||
virtual void exit();
|
||||
|
||||
virtual void interrupt();
|
||||
virtual void revert();
|
||||
|
||||
private:
|
||||
Storage* m_storage;
|
||||
std::queue<FilePath> m_filePaths;
|
||||
const size_t m_fileCount;
|
||||
|
||||
utility::TimePoint m_start;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
@@ -23,12 +23,13 @@ class StorageAccess
|
||||
public:
|
||||
virtual ~StorageAccess();
|
||||
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
|
||||
virtual Id getIdForEdgeWithName(const std::string& name) const = 0;
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const = 0;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const = 0;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const = 0;
|
||||
|
||||
virtual std::string getNameForNodeWithId(Id id) const = 0;
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(
|
||||
const std::string& query, const std::string& word) const = 0;
|
||||
|
||||
@@ -32,21 +32,22 @@ void StorageAccessProxy::setSubject(StorageAccess* subject)
|
||||
m_subject = subject;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::getIdForNodeWithName(const std::string& name) const
|
||||
Id StorageAccessProxy::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getIdForNodeWithName(name);
|
||||
return m_subject->getIdForNodeWithNameHierarchy(nameHierarchy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::getIdForEdgeWithName(const std::string& name) const
|
||||
{
|
||||
Id StorageAccessProxy::getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy
|
||||
) const {
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getIdForEdgeWithName(name);
|
||||
return m_subject->getIdForEdge(type, fromNameHierarchy, toNameHierarchy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -71,14 +72,14 @@ Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
return Node::NODE_UNDEFINED;
|
||||
}
|
||||
|
||||
std::string StorageAccessProxy::getNameForNodeWithId(Id id) const
|
||||
NameHierarchy StorageAccessProxy::getNameHierarchyForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNameForNodeWithId(id);
|
||||
return m_subject->getNameHierarchyForNodeWithId(id);
|
||||
}
|
||||
|
||||
return "";
|
||||
return NameHierarchy();
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> StorageAccessProxy::getAutocompletionMatches(
|
||||
|
||||
@@ -13,12 +13,13 @@ public:
|
||||
void setSubject(StorageAccess* subject);
|
||||
|
||||
// StorageAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const;
|
||||
virtual Id getIdForEdgeWithName(const std::string& name) const;
|
||||
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(
|
||||
const std::string& query, const std::string& word) const;
|
||||
|
||||
@@ -117,24 +117,6 @@ std::string Edge::getName() const
|
||||
return getTypeString() + ":" + getFrom()->getFullName() + "->" + getTo()->getFullName();
|
||||
}
|
||||
|
||||
void Edge::splitName(const std::string& name, EdgeType* type, std::string* fromName, std::string* toName)
|
||||
{
|
||||
EdgeTypeMask mask = 1;
|
||||
std::string typeStr = utility::substrBefore(name, ':');
|
||||
|
||||
while (typeStr != getTypeString(static_cast<EdgeType>(mask)))
|
||||
{
|
||||
mask = mask << 1;
|
||||
}
|
||||
|
||||
*type = static_cast<EdgeType>(mask);
|
||||
|
||||
std::string names = utility::substrAfter(name, ':');
|
||||
|
||||
*fromName = utility::substrBefore(names, '-');
|
||||
*toName = utility::substrAfter(utility::substrAfter(names, '-'), '>');
|
||||
}
|
||||
|
||||
bool Edge::isNode() const
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
Node* getTo() const;
|
||||
|
||||
std::string getName() const;
|
||||
static void splitName(const std::string& name, EdgeType* type, std::string* fromName, std::string* toName);
|
||||
|
||||
// Token implementation
|
||||
virtual bool isNode() const;
|
||||
|
||||
@@ -156,6 +156,11 @@ std::string Node::getFullName() const
|
||||
return m_nameHierarchy.getFullName();
|
||||
}
|
||||
|
||||
NameHierarchy Node::getNameHierarchy() const
|
||||
{
|
||||
return m_nameHierarchy;
|
||||
}
|
||||
|
||||
const std::vector<Edge*>& Node::getEdges() const
|
||||
{
|
||||
return m_edges;
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
|
||||
std::string getName() const;
|
||||
std::string getFullName() const;
|
||||
NameHierarchy getNameHierarchy() const;
|
||||
|
||||
const std::vector<Edge*>& getEdges() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user