logic: Retrieving StorageNodes for Autocompletion and FileInfos for modification time at once
Had only a small impact on performance unfortunately.
This commit is contained in:
@@ -181,7 +181,7 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(message->filePath);
|
||||
params.code = textAccess->getText();
|
||||
|
||||
params.modificationTime = m_storageAccess->getFileModificationTime(message->filePath);
|
||||
params.modificationTime = m_storageAccess->getFileInfoForFilePath(message->filePath).lastWriteTime;
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
@@ -326,7 +326,6 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath());
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
@@ -341,6 +340,8 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
|
||||
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sort);
|
||||
|
||||
addModificationTimes(snippets);
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
@@ -425,7 +426,6 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_pt
|
||||
}
|
||||
|
||||
const int snippetExpandRange = ApplicationSettings::getInstance()->getCodeSnippetExpandRange();
|
||||
TimePoint fileModificationTime = m_storageAccess->getFileModificationTime(activeTokenLocations->getFilePath());
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
for (const SnippetMerger::Range& range: ranges)
|
||||
{
|
||||
@@ -434,7 +434,6 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_pt
|
||||
params.refCount = activeTokenLocations->getUnscopedStartTokenLocationCount();
|
||||
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
|
||||
params.endLineNumber = std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
|
||||
params.modificationTime = fileModificationTime;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> tempFile =
|
||||
m_storageAccess->getTokenLocationsForLinesInFile(activeTokenLocations->getFilePath().str(), params.startLineNumber, params.endLineNumber);
|
||||
@@ -585,7 +584,6 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath());
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
@@ -593,6 +591,8 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForErrorLocations(
|
||||
}
|
||||
);
|
||||
|
||||
addModificationTimes(snippets);
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
@@ -651,3 +651,24 @@ std::vector<std::string> CodeController::getProjectDescription(TokenLocationFile
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
void CodeController::addModificationTimes(std::vector<CodeSnippetParams>& snippets) const
|
||||
{
|
||||
std::vector<FilePath> filePaths;
|
||||
for (const CodeSnippetParams& snippet : snippets)
|
||||
{
|
||||
filePaths.push_back(snippet.locationFile->getFilePath());
|
||||
}
|
||||
std::vector<FileInfo> fileInfos = m_storageAccess->getFileInfosForFilePaths(filePaths);
|
||||
|
||||
std::map<FilePath, FileInfo> fileInfoMap;
|
||||
for (FileInfo& fileInfo : fileInfos)
|
||||
{
|
||||
fileInfoMap.emplace(fileInfo.path, fileInfo);
|
||||
}
|
||||
|
||||
for (CodeSnippetParams& snippet : snippets)
|
||||
{
|
||||
snippet.modificationTime = fileInfoMap[snippet.locationFile->getFilePath()].lastWriteTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ private:
|
||||
|
||||
std::vector<std::string> getProjectDescription(TokenLocationFile* locationFile) const;
|
||||
|
||||
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
};
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ StorageNode SqliteStorage::getFirstNode() const
|
||||
return nodes[0];
|
||||
}
|
||||
|
||||
return StorageNode(0, 0, "", definitionTypeToInt(DEFINITION_NONE));
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
std::vector<StorageNode> SqliteStorage::getAllNodes() const
|
||||
@@ -422,7 +422,7 @@ StorageNode SqliteStorage::getNodeById(Id id) const
|
||||
{
|
||||
return getFirstNode("WHERE id == " + std::to_string(id));
|
||||
}
|
||||
return StorageNode(0, 0, "", definitionTypeToInt(DEFINITION_NONE));
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serializedName) const
|
||||
@@ -455,19 +455,24 @@ StorageFile SqliteStorage::getFileById(const Id id) const
|
||||
);
|
||||
}
|
||||
|
||||
StorageFile SqliteStorage::getFileByPath(const std::string& filePath) const
|
||||
StorageFile SqliteStorage::getFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
StorageFile storageFile = getFirstFile(
|
||||
"SELECT node.id, node.serialized_name, file.path, file.modification_time FROM node INNER JOIN file ON node.id = file.id "
|
||||
"WHERE file.path == '" + filePath + "';"
|
||||
"WHERE file.path == '" + filePath.str() + "';"
|
||||
);
|
||||
|
||||
return storageFile;
|
||||
}
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getFilesByPaths(const std::vector<FilePath>& filePaths) const
|
||||
{
|
||||
return getAllFiles("WHERE file.path IN ('" + utility::join(utility::toStrings(filePaths), "', '") + "')");
|
||||
}
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getAllFiles() const
|
||||
{
|
||||
return getAllFiles("SELECT file.id, node.serialized_name, file.path, file.modification_time FROM file INNER JOIN node ON file.id = node.id;");
|
||||
return getAllFiles("");
|
||||
}
|
||||
|
||||
std::shared_ptr<TextAccess> SqliteStorage::getFileContentByPath(const std::string& filePath) const
|
||||
@@ -909,10 +914,12 @@ StorageFile SqliteStorage::getFirstFile(const std::string& query) const
|
||||
|
||||
std::vector<StorageFile> SqliteStorage::getAllFiles(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT file.id, node.serialized_name, file.path, file.modification_time FROM file "
|
||||
"INNER JOIN node ON file.id = node.id " + query + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<StorageFile> files;
|
||||
|
||||
CppSQLite3Query q = m_database.execQuery(query.c_str());
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
@@ -1011,5 +1018,5 @@ StorageNode SqliteStorage::getFirstNode(const std::string& query) const
|
||||
{
|
||||
return nodes[0];
|
||||
}
|
||||
return StorageNode(0, 0, "", definitionTypeToInt(DEFINITION_NONE));
|
||||
return StorageNode();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ public:
|
||||
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
|
||||
|
||||
StorageFile getFileById(const Id id) const;
|
||||
StorageFile getFileByPath(const std::string& filePath) const;
|
||||
StorageFile getFileByPath(const FilePath& filePath) const;
|
||||
|
||||
std::vector<StorageFile> getFilesByPaths(const std::vector<FilePath>& filePaths) const;
|
||||
std::vector<StorageFile> getAllFiles() const;
|
||||
std::shared_ptr<TextAccess> getFileContentByPath(const std::string& filePath) const;
|
||||
|
||||
|
||||
+66
-34
@@ -260,50 +260,69 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
|
||||
}
|
||||
);
|
||||
|
||||
std::vector<SearchMatch> matches;
|
||||
for (size_t i = 0; i < results.size(); i++)
|
||||
std::map<Id, StorageNode> storageNodesMap;
|
||||
{
|
||||
std::vector<Id> elementIds;
|
||||
|
||||
for (const SearchResult& result : results)
|
||||
{
|
||||
elementIds.insert(elementIds.end(), result.elementIds.begin(), result.elementIds.end());
|
||||
}
|
||||
|
||||
std::vector<StorageNode> storageNodes = m_sqliteStorage.getNodesByIds(elementIds);
|
||||
|
||||
for (StorageNode& node : storageNodes)
|
||||
{
|
||||
if (node.id > 0)
|
||||
{
|
||||
storageNodesMap.emplace(node.id, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> matches;
|
||||
for (const SearchResult& result : results)
|
||||
{
|
||||
if (result.elementIds.size() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SearchMatch match;
|
||||
|
||||
if (results[i].elementIds.size() > 0)
|
||||
const StorageNode* firstNode = nullptr;
|
||||
for (const Id& elementId : result.elementIds)
|
||||
{
|
||||
StorageNode firstNode(0, 0, "", 0);
|
||||
for (std::set<Id>::const_iterator itElementIds = results[i].elementIds.begin();
|
||||
itElementIds != results[i].elementIds.end();
|
||||
itElementIds++)
|
||||
if (elementId != 0)
|
||||
{
|
||||
Id elementId = *itElementIds;
|
||||
if (elementId != 0)
|
||||
{
|
||||
StorageNode node = m_sqliteStorage.getNodeById(elementId);
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(node.serializedName));
|
||||
const StorageNode& node = storageNodesMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(node.serializedName));
|
||||
|
||||
if (firstNode.id == 0)
|
||||
{
|
||||
firstNode = node;
|
||||
}
|
||||
if (!firstNode)
|
||||
{
|
||||
firstNode = &node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match.text = results[i].text;
|
||||
match.indices = results[i].indices;
|
||||
match.text = result.text;
|
||||
match.indices = result.indices;
|
||||
|
||||
if (firstNode.id != 0)
|
||||
if (firstNode)
|
||||
{
|
||||
match.nodeType = Node::intToType(firstNode->type);
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
|
||||
if (intToDefinitionType(firstNode->definitionType) == DEFINITION_NONE && match.nodeType != Node::NODE_UNDEFINED)
|
||||
{
|
||||
match.nodeType = Node::intToType(firstNode.type);
|
||||
match.typeName = Node::getTypeString(match.nodeType);
|
||||
|
||||
if (intToDefinitionType(firstNode.definitionType) == DEFINITION_NONE && match.nodeType != Node::NODE_UNDEFINED)
|
||||
{
|
||||
match.typeName = "undefined " + match.typeName;
|
||||
}
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
match.searchType = SearchMatch::SEARCH_COMMAND;
|
||||
match.typeName = "command";
|
||||
match.typeName = "undefined " + match.typeName;
|
||||
}
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
match.searchType = SearchMatch::SEARCH_COMMAND;
|
||||
match.typeName = "command";
|
||||
}
|
||||
|
||||
matches.push_back(match);
|
||||
@@ -742,9 +761,22 @@ std::shared_ptr<TextAccess> Storage::getFileContent(const FilePath& filePath) co
|
||||
return m_sqliteStorage.getFileContentByPath(filePath.str());
|
||||
}
|
||||
|
||||
TimePoint Storage::getFileModificationTime(const FilePath& filePath) const
|
||||
FileInfo Storage::getFileInfoForFilePath(const FilePath& filePath) const
|
||||
{
|
||||
return TimePoint(m_sqliteStorage.getFileByPath(filePath.str()).modificationTime);
|
||||
return FileInfo(filePath, m_sqliteStorage.getFileByPath(filePath).modificationTime);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> Storage::getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getFilesByPaths(filePaths);
|
||||
for (const StorageFile& file : storageFiles)
|
||||
{
|
||||
fileInfos.push_back(FileInfo(FilePath(file.filePath), file.modificationTime));
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
}
|
||||
|
||||
ErrorCountInfo Storage::getErrorCount() const
|
||||
|
||||
@@ -79,7 +79,9 @@ public:
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
virtual TimePoint getFileModificationTime(const FilePath& filePath) const;
|
||||
|
||||
virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const;
|
||||
virtual std::vector<FileInfo> getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const;
|
||||
|
||||
virtual ErrorCountInfo getErrorCount() const;
|
||||
virtual StorageStats getStorageStats() const;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "data/DefinitionType.h"
|
||||
|
||||
struct StorageEdge
|
||||
{
|
||||
StorageEdge(Id id, int type, Id sourceNodeId, Id targetNodeId)
|
||||
@@ -22,6 +24,12 @@ struct StorageEdge
|
||||
|
||||
struct StorageNode
|
||||
{
|
||||
StorageNode()
|
||||
: id(0)
|
||||
, type(0)
|
||||
, definitionType(definitionTypeToInt(DEFINITION_NONE))
|
||||
{}
|
||||
|
||||
StorageNode(Id id, int type, const std::string& serializedName, int definitionType)
|
||||
: id(id)
|
||||
, type(type)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "utility/types.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
@@ -14,7 +15,6 @@
|
||||
#include "data/ErrorInfo.h"
|
||||
#include "data/StorageStats.h"
|
||||
|
||||
struct FileInfo;
|
||||
class Graph;
|
||||
class TextAccess;
|
||||
class TokenLocation;
|
||||
@@ -61,7 +61,9 @@ public:
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
|
||||
virtual TimePoint getFileModificationTime(const FilePath& filePath) const = 0;
|
||||
|
||||
virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const = 0;
|
||||
virtual std::vector<FileInfo> getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const = 0;
|
||||
|
||||
virtual ErrorCountInfo getErrorCount() const = 0;
|
||||
virtual StorageStats getStorageStats() const = 0;
|
||||
|
||||
@@ -255,14 +255,24 @@ std::shared_ptr<TextAccess> StorageAccessProxy::getFileContent(const FilePath& f
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TimePoint StorageAccessProxy::getFileModificationTime(const FilePath& filePath) const
|
||||
FileInfo StorageAccessProxy::getFileInfoForFilePath(const FilePath& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getFileModificationTime(filePath);
|
||||
return m_subject->getFileInfoForFilePath(filePath);
|
||||
}
|
||||
|
||||
return TimePoint(boost::posix_time::not_a_date_time);
|
||||
return FileInfo();
|
||||
}
|
||||
|
||||
std::vector<FileInfo> StorageAccessProxy::getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getFileInfosForFilePaths(filePaths);
|
||||
}
|
||||
|
||||
return std::vector<FileInfo>();
|
||||
}
|
||||
|
||||
ErrorCountInfo StorageAccessProxy::getErrorCount() const
|
||||
|
||||
@@ -48,7 +48,9 @@ public:
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
virtual TimePoint getFileModificationTime(const FilePath& filePath) const;
|
||||
|
||||
virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const;
|
||||
virtual std::vector<FileInfo> getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const;
|
||||
|
||||
virtual ErrorCountInfo getErrorCount() const;
|
||||
virtual StorageStats getStorageStats() const;
|
||||
|
||||
@@ -358,7 +358,7 @@ Id ParserClientImpl::onFileParsed(const FileInfo& fileInfo) // TODO: move up to
|
||||
{
|
||||
log("file", fileInfo.path.str(), ParseLocation());
|
||||
|
||||
addFile(fileInfo.path.fileName(), fileInfo.path.str(), utility::timeToString(fileInfo.lastWriteTime));
|
||||
addFile(fileInfo.path.fileName(), fileInfo.path.str(), fileInfo.lastWriteTime.toString());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -367,8 +367,8 @@ Id ParserClientImpl::onFileIncludeParsed(const ParseLocation& location, const Fi
|
||||
{
|
||||
log("include", includedFileInfo.path.str(), location);
|
||||
|
||||
Id fileNodeId = addFile(fileInfo.path.fileName(), fileInfo.path.str(), utility::timeToString(fileInfo.lastWriteTime));
|
||||
Id includedFileNodeId = addFile(includedFileInfo.path.fileName(), includedFileInfo.path.str(), utility::timeToString(includedFileInfo.lastWriteTime));
|
||||
Id fileNodeId = addFile(fileInfo.path.fileName(), fileInfo.path.str(), fileInfo.lastWriteTime.toString());
|
||||
Id includedFileNodeId = addFile(includedFileInfo.path.fileName(), includedFileInfo.path.str(), includedFileInfo.lastWriteTime.toString());
|
||||
Id edgeId = addEdge(Edge::EDGE_INCLUDE, fileNodeId, includedFileNodeId);
|
||||
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
FileInfo::FileInfo()
|
||||
: path(FilePath(""))
|
||||
, lastWriteTime(boost::posix_time::not_a_date_time)
|
||||
{
|
||||
}
|
||||
|
||||
FileInfo::FileInfo(const FilePath& path)
|
||||
: path(path)
|
||||
, lastWriteTime(boost::posix_time::not_a_date_time)
|
||||
{
|
||||
}
|
||||
|
||||
FileInfo::FileInfo(const FilePath& path, boost::posix_time::ptime lastWriteTime)
|
||||
FileInfo::FileInfo(const FilePath& path, const TimePoint& lastWriteTime)
|
||||
: path(path)
|
||||
, lastWriteTime(lastWriteTime)
|
||||
{
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
#include "boost/date_time.hpp"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
struct FileInfo
|
||||
{
|
||||
FileInfo();
|
||||
FileInfo(const FilePath& path);
|
||||
FileInfo(const FilePath& path, boost::posix_time::ptime lastWriteTime);
|
||||
FileInfo(const FilePath& path, const TimePoint& lastWriteTime);
|
||||
|
||||
FilePath path;
|
||||
boost::posix_time::ptime lastWriteTime;
|
||||
TimePoint lastWriteTime;
|
||||
};
|
||||
|
||||
#endif // FILE_INFO_H
|
||||
|
||||
Reference in New Issue
Block a user