Skip to content

Commit

Permalink
Fixed autoincrement id fetching cache problem in import/export module (
Browse files Browse the repository at this point in the history
…#3730)

Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
Co-authored-by: Colin Mollenhour <colin@mollenhour.com>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 8054bb6 commit f34dbe3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,15 @@
"contributions": [
"code"
]
},
{
"login": "leissbua",
"name": "Michael Leiss",
"avatar_url": "https://avatars.githubusercontent.com/u/68073221?v=4",
"profile": "https://github.com/leissbua",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all_contributors-156-orange.svg" alt="All Contributors"></a>
<a href="#contributors-"><img src="https://img.shields.io/badge/all_contributors-157-orange.svg" alt="All Contributors"></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<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>
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/license.svg" alt="License"></a>
Expand Down Expand Up @@ -590,6 +590,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<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>
<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>
<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>
<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>
</tr>
</tbody>
</table>
Expand Down
23 changes: 22 additions & 1 deletion app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ 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
*
Expand All @@ -49,11 +56,25 @@ public function getMaxDataSize()
public function getNextAutoincrement($tableName)
{
$adapter = $this->_getReadAdapter();
$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(): void
{
if (!self::$instantInformationSchemaStatsExpiry) {
try {
$this->_getReadAdapter()->query('SET information_schema_stats_expiry = 0;');
} catch (Exception $e) {
}
self::$instantInformationSchemaStatsExpiry = true;
}
}
}

0 comments on commit f34dbe3

Please sign in to comment.