@tsteur opened this Issue on October 12th 2021 Member

We noticed on Cloud that https://github.com/matomo-org/matomo/blob/4.x-dev/core/Db/TransactionLevel.php#L57 might be called very often. Especially when having many funnels but also in general. It can cause a bit of load. It be better to instead cache this information whether uncommitted can be set or not instead of retrying for support every time. We should cache this eg on the $this->db as it's DB dependent as if someone configures different DBs for writer and reader for example then we cannot reuse / cache the same result.

I'm meaning something in this direction (not tested):

diff --git a/core/Db/TransactionLevel.php b/core/Db/TransactionLevel.php
index c19699084..fd730ced9 100644
--- a/core/Db/TransactionLevel.php
+++ b/core/Db/TransactionLevel.php
@@ -40,6 +40,10 @@ class TransactionLevel

     public function setUncommitted()
     {
+        if ($this->db->supportsUncommitted === false) {
+            return false;
+        }
+
         try {
             $backup = $this->db->fetchOne('SELECT @<a class='mention' href='https://github.com/TX_ISOLATION'>@TX_ISOLATION</a>');
         } catch (\Exception $e) {
@@ -54,8 +58,13 @@ class TransactionLevel
             $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED');
             $this->statusBackup = $backup;

-            Option::set(self::TEST_OPTION_NAME, '1'); // try setting something w/ the new transaction isolation level
+            if (!isset($this->db->supportsUncommitted)) {
+                Option::set(self::TEST_OPTION_NAME, '1'); // try setting something w/ the new transaction isolation level
+
+                $this->db->supportsUncommitted = true;
+            }
         } catch (\Exception $e) {
+            $this->db->supportsUncommitted = false;
             // catch eg 1665 Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED
             $this->restorePreviousStatus();
             return false;
diff --git a/plugins/Cloud b/plugins/Clo
Powered by GitHub Issue Mirror