QmlDesigner: Avoid writes into the project storage

If the values are the same we should avoid writes to the database
because they are not so cheap. Also recognize that "IS NOT" is used
instead of "<>" because we want to test for null values too.

Change-Id: I6699c6c40ad42f5d07910905b10cc7d423373320
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2021-07-06 11:39:24 +02:00
parent 3527ea8942
commit a8d6bb06df

View File

@@ -1072,6 +1072,9 @@ private:
static_cast<int>(type.accessSemantics), static_cast<int>(type.accessSemantics),
&type.sourceId); &type.sourceId);
if (!type.typeId)
type.typeId = selectTypeIdByImportIdAndNameStatement.template value<TypeId>(&type.importId,
type.typeName);
upsertNativeType(type.importId, type.typeName, type.typeId); upsertNativeType(type.importId, type.typeName, type.typeId);
for (const auto &exportedType : type.exportedTypes) for (const auto &exportedType : type.exportedTypes)
@@ -1516,10 +1519,15 @@ public:
"INSERT INTO types(importId, name, accessSemantics, sourceId) VALUES(?1, ?2, " "INSERT INTO types(importId, name, accessSemantics, sourceId) VALUES(?1, ?2, "
"?3, nullif(?4, -1)) ON " "?3, nullif(?4, -1)) ON "
"CONFLICT DO UPDATE SET prototypeId=excluded.prototypeId, " "CONFLICT DO UPDATE SET prototypeId=excluded.prototypeId, "
"accessSemantics=excluded.accessSemantics, sourceId=excluded.sourceId RETURNING typeId", "accessSemantics=excluded.accessSemantics, sourceId=excluded.sourceId WHERE "
"prototypeId iS NOT excluded.prototypeId OR accessSemantics IS NOT "
"excluded.accessSemantics OR "
"sourceId IS NOT excluded.sourceId RETURNING typeId",
database}; database};
WriteStatement updatePrototypeStatement{ WriteStatement updatePrototypeStatement{
"UPDATE types SET prototypeId=?2, prototypeNameId=?3 WHERE typeId=?1", database}; "UPDATE types SET prototypeId=?2, prototypeNameId=?3 WHERE typeId=?1 AND (prototypeId IS "
"NOT ?2 OR prototypeNameId IS NOT ?3)",
database};
mutable ReadStatement<1> selectTypeIdByExportedNameStatement{ mutable ReadStatement<1> selectTypeIdByExportedNameStatement{
"SELECT typeId FROM typeNames WHERE name=?1 AND kind=1", database}; "SELECT typeId FROM typeNames WHERE name=?1 AND kind=1", database};
mutable ReadStatement<1> selectPrototypeIdStatement{ mutable ReadStatement<1> selectPrototypeIdStatement{
@@ -1553,7 +1561,7 @@ public:
database}; database};
WriteStatement upsertTypeNamesStatement{ WriteStatement upsertTypeNamesStatement{
"INSERT INTO typeNames(importId, name, typeId, kind) VALUES(?1, ?2, ?3, ?4) ON CONFLICT DO " "INSERT INTO typeNames(importId, name, typeId, kind) VALUES(?1, ?2, ?3, ?4) ON CONFLICT DO "
"UPDATE SET typeId=excluded.typeId", "UPDATE SET typeId=excluded.typeId WHERE typeId IS NOT excluded.typeId",
database}; database};
mutable ReadStatement<1> selectPrototypeIdsStatement{ mutable ReadStatement<1> selectPrototypeIdsStatement{
"WITH RECURSIVE " "WITH RECURSIVE "