forked from qt-creator/qt-creator
QmlDesigner: Add file status support to the project storage
Task-number: QDS-4785 Change-Id: Idaadf6992fad938e3620169a415f9d3cf7b9927f Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -36,21 +36,25 @@ namespace QmlDesigner {
|
||||
class FileStatus
|
||||
{
|
||||
public:
|
||||
FileStatus(SourceId sourceId, off_t size, std::time_t lastModified)
|
||||
: sourceId(sourceId)
|
||||
, size(size)
|
||||
, lastModified(lastModified)
|
||||
explicit FileStatus(SourceId sourceId, off_t size, std::time_t lastModified)
|
||||
: sourceId{sourceId}
|
||||
, size{size}
|
||||
, lastModified{lastModified}
|
||||
{}
|
||||
|
||||
friend
|
||||
bool operator==(const FileStatus &first, const FileStatus &second)
|
||||
explicit FileStatus(int sourceId, off_t size, std::time_t lastModified)
|
||||
: sourceId{sourceId}
|
||||
, size{size}
|
||||
, lastModified{lastModified}
|
||||
{}
|
||||
|
||||
friend bool operator==(const FileStatus &first, const FileStatus &second)
|
||||
{
|
||||
return first.sourceId == second.sourceId && first.size == second.size
|
||||
&& first.lastModified == second.lastModified;
|
||||
}
|
||||
|
||||
friend
|
||||
bool operator<(const FileStatus &first, const FileStatus &second)
|
||||
friend bool operator<(const FileStatus &first, const FileStatus &second)
|
||||
{
|
||||
return first.sourceId < second.sourceId;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "filestatus.h"
|
||||
#include "projectstorageexceptions.h"
|
||||
#include "projectstorageids.h"
|
||||
#include "projectstoragetypes.h"
|
||||
@@ -59,7 +60,8 @@ public:
|
||||
void synchronize(Storage::ImportDependencies importDependencies,
|
||||
Storage::Documents documents,
|
||||
Storage::Types types,
|
||||
SourceIds sourceIds)
|
||||
SourceIds sourceIds,
|
||||
FileStatuses fileStatuses)
|
||||
{
|
||||
Sqlite::ImmediateTransaction transaction{database};
|
||||
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
return &sourceId;
|
||||
});
|
||||
|
||||
synchronizeFileStatuses(fileStatuses, sourceIdValues);
|
||||
synchronizeImports(importDependencies, deletedTypeIds, sourceIdValues);
|
||||
synchronizeDocuments(documents, sourceIdValues);
|
||||
synchronizeTypes(types,
|
||||
@@ -291,6 +294,11 @@ public:
|
||||
return imports;
|
||||
}
|
||||
|
||||
auto fetchAllFileStatuses() const
|
||||
{
|
||||
return selectAllFileStatusesStatement.template rangeWithTransaction<FileStatus>();
|
||||
}
|
||||
|
||||
private:
|
||||
class AliasPropertyDeclaration
|
||||
{
|
||||
@@ -421,6 +429,41 @@ private:
|
||||
syncDeclarations(type, insertedAliasPropertyDeclarations, updatedAliasPropertyDeclarations);
|
||||
}
|
||||
|
||||
void synchronizeFileStatuses(FileStatuses &fileStatuses, const std::vector<int> &sourceIdValues)
|
||||
{
|
||||
auto compareKey = [](auto &&first, auto &&second) {
|
||||
return first.sourceId.id - second.sourceId.id;
|
||||
};
|
||||
|
||||
std::sort(fileStatuses.begin(), fileStatuses.end(), [&](auto &&first, auto &&second) {
|
||||
return first.sourceId < second.sourceId;
|
||||
});
|
||||
|
||||
auto range = selectFileStatusesForSourceIdsStatement.template range<FileStatus>(
|
||||
Utils::span(sourceIdValues));
|
||||
|
||||
auto insert = [&](const FileStatus &fileStatus) {
|
||||
insertFileStatusStatement.write(&fileStatus.sourceId,
|
||||
fileStatus.size,
|
||||
fileStatus.lastModified);
|
||||
};
|
||||
|
||||
auto update = [&](const FileStatus &fileStatusFromDatabase, const FileStatus &fileStatus) {
|
||||
if (fileStatusFromDatabase.lastModified != fileStatus.lastModified
|
||||
|| fileStatusFromDatabase.size != fileStatus.size) {
|
||||
updateFileStatusStatement.write(&fileStatus.sourceId,
|
||||
fileStatus.size,
|
||||
fileStatus.lastModified);
|
||||
}
|
||||
};
|
||||
|
||||
auto remove = [&](const FileStatus &fileStatus) {
|
||||
deleteFileStatusStatement.write(&fileStatus.sourceId);
|
||||
};
|
||||
|
||||
Sqlite::insertUpdateDelete(range, fileStatuses, compareKey, insert, update, remove);
|
||||
}
|
||||
|
||||
void synchronizeImports(Storage::ImportDependencies &imports,
|
||||
TypeIds &deletedTypeIds,
|
||||
const std::vector<int> &importIdValues)
|
||||
@@ -1498,6 +1541,7 @@ private:
|
||||
createFunctionsTable(database);
|
||||
createSignalsTable(database);
|
||||
createSourceImportsTable(database);
|
||||
createFileStatusesTable(database);
|
||||
|
||||
transaction.commit();
|
||||
|
||||
@@ -1694,6 +1738,24 @@ private:
|
||||
|
||||
table.initialize(database);
|
||||
}
|
||||
|
||||
void createFileStatusesTable(Database &database)
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setUseIfNotExists(true);
|
||||
table.setName("fileStatuses");
|
||||
table.addColumn("sourceId",
|
||||
Sqlite::ColumnType::Integer,
|
||||
{Sqlite::PrimaryKey{},
|
||||
Sqlite::ForeignKey{"sources",
|
||||
"sourceId",
|
||||
Sqlite::ForeignKeyAction::NoAction,
|
||||
Sqlite::ForeignKeyAction::Cascade}});
|
||||
table.addColumn("size");
|
||||
table.addColumn("lastModified");
|
||||
|
||||
table.initialize(database);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -2118,6 +2180,17 @@ public:
|
||||
" USING(propertyDeclarationId)) "
|
||||
"SELECT propertyDeclarationId FROM properties",
|
||||
database};
|
||||
mutable ReadStatement<3> selectAllFileStatusesStatement{
|
||||
"SELECT sourceId, size, lastModified FROM fileStatuses", database};
|
||||
mutable ReadStatement<3> selectFileStatusesForSourceIdsStatement{
|
||||
"SELECT sourceId, size, lastModified FROM fileStatuses WHERE sourceId IN carray(?1) ORDER "
|
||||
"BY sourceId",
|
||||
database};
|
||||
WriteStatement insertFileStatusStatement{
|
||||
"INSERT INTO fileStatuses(sourceId, size, lastModified) VALUES(?1, ?2, ?3)", database};
|
||||
WriteStatement deleteFileStatusStatement{"DELETE FROM fileStatuses WHERE sourceId=?1", database};
|
||||
WriteStatement updateFileStatusStatement{
|
||||
"UPDATE fileStatuses SET size=?2, lastModified=?3 WHERE sourceId=?1", database};
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <clangtools/clangtoolsdiagnostic.h>
|
||||
#include <debugger/analyzer/diagnosticlocation.h>
|
||||
#include <modelnode.h>
|
||||
#include <projectstorage/filestatus.h>
|
||||
#include <projectstorage/projectstoragepathwatchertypes.h>
|
||||
#include <projectstorage/projectstoragetypes.h>
|
||||
#include <projectstorage/sourcepathcachetypes.h>
|
||||
@@ -948,6 +949,12 @@ const char *sourceTypeToText(SourceType sourceType)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const FileStatus &fileStatus)
|
||||
{
|
||||
return out << "(" << fileStatus.sourceId << ", " << fileStatus.size << ", "
|
||||
<< fileStatus.lastModified << ")";
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, SourceType sourceType)
|
||||
{
|
||||
return out << sourceTypeToText(sourceType);
|
||||
|
||||
@@ -220,6 +220,7 @@ class WatcherEntry;
|
||||
class IdPaths;
|
||||
class ProjectChunkId;
|
||||
enum class SourceType : int;
|
||||
class FileStatus;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ModelNode &node);
|
||||
std::ostream &operator<<(std::ostream &out, const VariantProperty &property);
|
||||
@@ -234,6 +235,7 @@ std::ostream &operator<<(std::ostream &out, const WatcherEntry &entry);
|
||||
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
|
||||
std::ostream &operator<<(std::ostream &out, const ProjectChunkId &id);
|
||||
std::ostream &operator<<(std::ostream &out, SourceType sourceType);
|
||||
std::ostream &operator<<(std::ostream &out, const FileStatus &fileStatus);
|
||||
|
||||
namespace Cache {
|
||||
class SourceContext;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user