From eaf41b1d28af1e1268901f2f02e15056508d572c Mon Sep 17 00:00:00 2001 From: Michael Leiss Date: Thu, 11 Jan 2024 15:45:44 +0100 Subject: [PATCH 01/19] Fix autoincrement fetching cache problem --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index c79acbe0518..c62c45ddece 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -49,11 +49,14 @@ public function getMaxDataSize() public function getNextAutoincrement($tableName) { $adapter = $this->_getReadAdapter(); + $adapter->query('SET information_schema_stats_expiry = 0;'); $entityStatus = $adapter->showTableStatus($tableName); - if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); } + + $adapter->query('SET information_schema_stats_expiry = 1;'); return $entityStatus['Auto_increment']; } + } From 0365433c425e308f6b49917988a0942e3687633f Mon Sep 17 00:00:00 2001 From: Michael Leiss Date: Thu, 11 Jan 2024 16:05:43 +0100 Subject: [PATCH 02/19] Fix autoincrement fetching cache problem --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index c62c45ddece..4e847cf7b59 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -54,9 +54,8 @@ public function getNextAutoincrement($tableName) if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); } - - $adapter->query('SET information_schema_stats_expiry = 1;'); - return $entityStatus['Auto_increment']; + + return $entityStatus['Auto_increment']; } } From aadd6db13a46ed57c01f2844e045feab2c2353e8 Mon Sep 17 00:00:00 2001 From: Michael Leiss Date: Thu, 11 Jan 2024 16:39:40 +0100 Subject: [PATCH 03/19] Add @leissbua as a contributor --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 259815fa56c..96f20c1a839 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1418,6 +1418,15 @@ "contributions": [ "code" ] + }, + { + "login": "leissbua", + "name": "leissbua", + "avatar_url": "https://avatars.githubusercontent.com/u/68073221?v=4", + "profile": "https://github.com/leissbua", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7 diff --git a/README.md b/README.md index 6b62fff0695..cb410956ea3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

-All Contributors +All Contributors Total Downloads License @@ -589,7 +589,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Juho Hölsä

Kane
-
Kevin Jakob
+
leissbua
From ba76d501203316fa9eaade3f9c4358515486b8d8 Mon Sep 17 00:00:00 2001 From: Michael Leiss Date: Thu, 11 Jan 2024 16:41:22 +0100 Subject: [PATCH 04/19] Adding leissbua to the contributors --- .all-contributorsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 96f20c1a839..882017d2b45 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1421,7 +1421,7 @@ }, { "login": "leissbua", - "name": "leissbua", + "name": "Michael Leiss", "avatar_url": "https://avatars.githubusercontent.com/u/68073221?v=4", "profile": "https://github.com/leissbua", "contributions": [ From 6a84331c1bb28fa52269e4cab37500363f302d5f Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:08:24 +0100 Subject: [PATCH 05/19] Fix CS --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 4e847cf7b59..177abe81154 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -54,8 +54,6 @@ public function getNextAutoincrement($tableName) if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); } - return $entityStatus['Auto_increment']; } - } From 5e69349f29b2b07387af9c3230541e0be789461a Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Fri, 12 Jan 2024 08:59:20 +0100 Subject: [PATCH 06/19] Fix CS --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 177abe81154..259b687d013 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -54,6 +54,6 @@ public function getNextAutoincrement($tableName) if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); } - return $entityStatus['Auto_increment']; + return $entityStatus['Auto_increment']; } } From 9ea11e7e440d68f139609049447633f728a4f9bb Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:56:11 +0100 Subject: [PATCH 07/19] Include semaphore to reset stats expiry to 0 only once --- .../Model/Resource/Helper/Mysql4.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 259b687d013..83351c1140b 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -27,6 +27,11 @@ class Mage_ImportExport_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Res public const DB_MAX_PACKET_SIZE = 1048576; // Maximal packet length by default in MySQL public const DB_MAX_PACKET_COEFFICIENT = 0.85; // The coefficient of useful data from maximum packet length + /** + * Semaphore to disable schema stats only once + */ + private static boolean $instantInformationSchemaStatsExpiry = false; + /** * Returns maximum size of packet, that we can send to DB * @@ -49,11 +54,23 @@ public function getMaxDataSize() public function getNextAutoincrement($tableName) { $adapter = $this->_getReadAdapter(); - $adapter->query('SET information_schema_stats_expiry = 0;'); + $this->setInformationSchemaStatsExpiry(); $entityStatus = $adapter->showTableStatus($tableName); if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); } return $entityStatus['Auto_increment']; } + + /** + * Set information_schema_stats_expiry to 0 if not already set. + */ + public function setInformationSchemaStatsExpiry() + { + if (!self::$instantInformationSchemaStatsExpiry) { + // Set information_schema_stats_expiry to 0 + $this->getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); + self::$instantInformationSchemaStatsExpiry = true; + } + } } From 5613726a579deea6b5a8d90346fff5bac0a0e18b Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:00:34 +0100 Subject: [PATCH 08/19] Fix typo --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 83351c1140b..a10cfa59ff8 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -69,7 +69,7 @@ public function setInformationSchemaStatsExpiry() { if (!self::$instantInformationSchemaStatsExpiry) { // Set information_schema_stats_expiry to 0 - $this->getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); + $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); self::$instantInformationSchemaStatsExpiry = true; } } From 6b5b2f5d149f964948bf0e1ef596f96a3f938cd5 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:34:22 +0100 Subject: [PATCH 09/19] Fix declaration of static member variable --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index a10cfa59ff8..cc758d9fc25 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -29,8 +29,10 @@ class Mage_ImportExport_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Res /** * Semaphore to disable schema stats only once + * + * @var bool */ - private static boolean $instantInformationSchemaStatsExpiry = false; + private static $instantInformationSchemaStatsExpiry = false; /** * Returns maximum size of packet, that we can send to DB From fc18e1fa9325a15c8b8372c1d66a1f402ad40f99 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:04:19 +0100 Subject: [PATCH 10/19] Fix CS Whitespace From c4a94158558d466455cab91ac44370d3c9305817 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:37:19 +0100 Subject: [PATCH 11/19] Catch errors for < mysql8 and remove comment --- .../Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index cc758d9fc25..d6d8fb8c160 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -56,7 +56,11 @@ public function getMaxDataSize() public function getNextAutoincrement($tableName) { $adapter = $this->_getReadAdapter(); - $this->setInformationSchemaStatsExpiry(); + try { + $this->setInformationSchemaStatsExpiry(); + } catch (Exception $e) { + //this will throw an exception for < mysql8 + } $entityStatus = $adapter->showTableStatus($tableName); if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); @@ -70,7 +74,6 @@ public function getNextAutoincrement($tableName) public function setInformationSchemaStatsExpiry() { if (!self::$instantInformationSchemaStatsExpiry) { - // Set information_schema_stats_expiry to 0 $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); self::$instantInformationSchemaStatsExpiry = true; } From 4ab4876ba9e8c4defc59f310e308bceb73c955bb Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:58:08 +0100 Subject: [PATCH 12/19] Fix CS --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index d6d8fb8c160..0d50eda1f74 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -26,7 +26,7 @@ class Mage_ImportExport_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Res */ public const DB_MAX_PACKET_SIZE = 1048576; // Maximal packet length by default in MySQL public const DB_MAX_PACKET_COEFFICIENT = 0.85; // The coefficient of useful data from maximum packet length - + /** * Semaphore to disable schema stats only once * @@ -45,7 +45,7 @@ public function getMaxDataSize() $maxPacket = empty($maxPacketData['Value']) ? self::DB_MAX_PACKET_SIZE : $maxPacketData['Value']; return floor($maxPacket * self::DB_MAX_PACKET_COEFFICIENT); } - + /** * Returns next autoincrement value for a table * @@ -67,7 +67,7 @@ public function getNextAutoincrement($tableName) } return $entityStatus['Auto_increment']; } - + /** * Set information_schema_stats_expiry to 0 if not already set. */ From 5c2f2d8ae5636fa25de2589514ac50cdcfb27107 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:04:41 +0100 Subject: [PATCH 13/19] Fix CS --- .../Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 0d50eda1f74..b079fc08840 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -26,14 +26,14 @@ class Mage_ImportExport_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Res */ public const DB_MAX_PACKET_SIZE = 1048576; // Maximal packet length by default in MySQL public const DB_MAX_PACKET_COEFFICIENT = 0.85; // The coefficient of useful data from maximum packet length - + /** * Semaphore to disable schema stats only once * * @var bool */ private static $instantInformationSchemaStatsExpiry = false; - + /** * Returns maximum size of packet, that we can send to DB * @@ -45,7 +45,7 @@ public function getMaxDataSize() $maxPacket = empty($maxPacketData['Value']) ? self::DB_MAX_PACKET_SIZE : $maxPacketData['Value']; return floor($maxPacket * self::DB_MAX_PACKET_COEFFICIENT); } - + /** * Returns next autoincrement value for a table * @@ -67,7 +67,7 @@ public function getNextAutoincrement($tableName) } return $entityStatus['Auto_increment']; } - + /** * Set information_schema_stats_expiry to 0 if not already set. */ From 35a96d9174248cbea763d0938aace22668a44407 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:11:45 +0100 Subject: [PATCH 14/19] Add return type void to method setInformationSchemaStatsExpiry Co-authored-by: Fabrizio Balliano --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index b079fc08840..164ad0ae524 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -71,7 +71,7 @@ public function getNextAutoincrement($tableName) /** * Set information_schema_stats_expiry to 0 if not already set. */ - public function setInformationSchemaStatsExpiry() + public function setInformationSchemaStatsExpiry(): void { if (!self::$instantInformationSchemaStatsExpiry) { $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); From 2eed005eafca97aa9c322a0c3f6002a8e2d3be83 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:22:27 +0100 Subject: [PATCH 15/19] Fix CS - removed whitespace --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 164ad0ae524..fa8f04e9ac6 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -57,7 +57,7 @@ public function getNextAutoincrement($tableName) { $adapter = $this->_getReadAdapter(); try { - $this->setInformationSchemaStatsExpiry(); + $this->setInformationSchemaStatsExpiry(); } catch (Exception $e) { //this will throw an exception for < mysql8 } From 311d238e07052f7385c523fcb6ee8428c5bed4fc Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:27:02 +0100 Subject: [PATCH 16/19] Readded Kevin Jakob --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cb410956ea3..e40dcdfdf16 100644 --- a/README.md +++ b/README.md @@ -589,6 +589,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Juho Hölsä

Kane
+
Kevin Jakob

leissbua
From d82648954ba0b521ecd27588e9a4e27086ecec74 Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:33:51 +0100 Subject: [PATCH 17/19] Update app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php Co-authored-by: Fabrizio Balliano --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index fa8f04e9ac6..ea56f12442d 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -74,7 +74,9 @@ public function getNextAutoincrement($tableName) public function setInformationSchemaStatsExpiry(): void { if (!self::$instantInformationSchemaStatsExpiry) { - $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); + try { + $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); + } catch (Exception $e) {} self::$instantInformationSchemaStatsExpiry = true; } } From 8d714ffe6eb1dce2b9919ddf9059cd479d30e79d Mon Sep 17 00:00:00 2001 From: leissbua <68073221+leissbua@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:37:14 +0100 Subject: [PATCH 18/19] Add try catch to actual disable cache call --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index ea56f12442d..2914ab641ec 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -56,11 +56,7 @@ public function getMaxDataSize() public function getNextAutoincrement($tableName) { $adapter = $this->_getReadAdapter(); - try { - $this->setInformationSchemaStatsExpiry(); - } catch (Exception $e) { - //this will throw an exception for < mysql8 - } + $this->setInformationSchemaStatsExpiry(); $entityStatus = $adapter->showTableStatus($tableName); if (empty($entityStatus['Auto_increment'])) { Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value')); From 35bdf93753510227ae33be7a257425d05bdff204 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 23 Jan 2024 14:44:12 +0000 Subject: [PATCH 19/19] PHPCS --- .../core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php index 2914ab641ec..b0be1fcf692 100644 --- a/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php @@ -72,7 +72,8 @@ public function setInformationSchemaStatsExpiry(): void if (!self::$instantInformationSchemaStatsExpiry) { try { $this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;'); - } catch (Exception $e) {} + } catch (Exception $e) { + } self::$instantInformationSchemaStatsExpiry = true; } }