From eba49776c18ad23bbae71b918b5b19037a58007c Mon Sep 17 00:00:00 2001 From: silverqx Date: Fri, 26 Jul 2024 21:51:05 +0200 Subject: [PATCH] drivers optimized cleanup before query execution Don't cleanup on the newly created instance. --- .../include_private/orm/drivers/sqlresult_p.hpp | 3 +++ .../mysql/src/orm/drivers/mysql/mysqlresult.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/common/include_private/orm/drivers/sqlresult_p.hpp b/drivers/common/include_private/orm/drivers/sqlresult_p.hpp index 9a21c0c7f..cc7c5c1a4 100644 --- a/drivers/common/include_private/orm/drivers/sqlresult_p.hpp +++ b/drivers/common/include_private/orm/drivers/sqlresult_p.hpp @@ -64,6 +64,9 @@ namespace Orm::Drivers bool isActive = false; /*! Is this result from the SELECT statement? */ bool isSelect = false; + /*! Determine if the instance needs cleanup before executing the query. It's + always true after the first query is executed. */ + bool needsCleanup = false; }; } // namespace Orm::Drivers diff --git a/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp b/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp index 72a0ae8b4..937cdd337 100644 --- a/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp +++ b/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp @@ -527,6 +527,13 @@ void MySqlResult::cleanupForNormal() { Q_D(MySqlResult); + /* Helps to avoid cleanup on the newly created instance, it's only false on the newly + created instance. */ + if (!d->needsCleanup) { + d->needsCleanup = true; + return; + } + d->recordCache.clear(); // Normal queries @@ -540,6 +547,13 @@ void MySqlResult::cleanupForPrepared() { Q_D(MySqlResult); + /* Helps to avoid cleanup on the newly created instance, it's only false on the newly + created instance. */ + if (!d->needsCleanup) { + d->needsCleanup = true; + return; + } + d->recordCache.clear(); // Prepared queries