Skip to content

Commit f34dbe3

Browse files
leissbuafballianocolinmollenhour
authored
Fixed autoincrement id fetching cache problem in import/export module (#3730)
Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com> Co-authored-by: Colin Mollenhour <colin@mollenhour.com>
1 parent 8054bb6 commit f34dbe3

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,15 @@
14181418
"contributions": [
14191419
"code"
14201420
]
1421+
},
1422+
{
1423+
"login": "leissbua",
1424+
"name": "Michael Leiss",
1425+
"avatar_url": "https://avatars.githubusercontent.com/u/68073221?v=4",
1426+
"profile": "https://github.com/leissbua",
1427+
"contributions": [
1428+
"code"
1429+
]
14211430
}
14221431
],
14231432
"contributorsPerLine": 7

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
22
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3-
<a href="#contributors-"><img src="https://img.shields.io/badge/all_contributors-156-orange.svg" alt="All Contributors"></a>
3+
<a href="#contributors-"><img src="https://img.shields.io/badge/all_contributors-157-orange.svg" alt="All Contributors"></a>
44
<!-- ALL-CONTRIBUTORS-BADGE:END -->
55
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/d/total.svg" alt="Total Downloads"></a>
66
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/license.svg" alt="License"></a>
@@ -590,6 +590,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
590590
<td align="center" valign="top" width="14.28%"><a href="https://juhoholsa.com/"><img src="https://avatars.githubusercontent.com/u/15036353?v=4" loading="lazy" width="100" alt=""/><br /><sub><b>Juho Hölsä</b></sub></a></td>
591591
<td align="center" valign="top" width="14.28%"><a href="https://github.com/seifer7"><img src="https://avatars.githubusercontent.com/u/13601073?v=4" loading="lazy" width="100" alt=""/><br /><sub><b>Kane</b></sub></a></td>
592592
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Sdfendor"><img src="https://avatars.githubusercontent.com/u/2728018?v=4" loading="lazy" width="100" alt=""/><br /><sub><b>Kevin Jakob</b></sub></a></td>
593+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/leissbua"><img src="https://avatars.githubusercontent.com/u/68073221?v=4" loading="lazy" width="100" alt=""/><br /><sub><b>leissbua</b></sub></a></td>
593594
</tr>
594595
</tbody>
595596
</table>

app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class Mage_ImportExport_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Res
2727
public const DB_MAX_PACKET_SIZE = 1048576; // Maximal packet length by default in MySQL
2828
public const DB_MAX_PACKET_COEFFICIENT = 0.85; // The coefficient of useful data from maximum packet length
2929

30+
/**
31+
* Semaphore to disable schema stats only once
32+
*
33+
* @var bool
34+
*/
35+
private static $instantInformationSchemaStatsExpiry = false;
36+
3037
/**
3138
* Returns maximum size of packet, that we can send to DB
3239
*
@@ -49,11 +56,25 @@ public function getMaxDataSize()
4956
public function getNextAutoincrement($tableName)
5057
{
5158
$adapter = $this->_getReadAdapter();
59+
$this->setInformationSchemaStatsExpiry();
5260
$entityStatus = $adapter->showTableStatus($tableName);
53-
5461
if (empty($entityStatus['Auto_increment'])) {
5562
Mage::throwException(Mage::helper('importexport')->__('Cannot get autoincrement value'));
5663
}
5764
return $entityStatus['Auto_increment'];
5865
}
66+
67+
/**
68+
* Set information_schema_stats_expiry to 0 if not already set.
69+
*/
70+
public function setInformationSchemaStatsExpiry(): void
71+
{
72+
if (!self::$instantInformationSchemaStatsExpiry) {
73+
try {
74+
$this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;');
75+
} catch (Exception $e) {
76+
}
77+
self::$instantInformationSchemaStatsExpiry = true;
78+
}
79+
}
5980
}

0 commit comments

Comments
 (0)