Skip to content

Commit db3e2b4

Browse files
committed
5886: Close MySQL connection after collection load and before commit
Resolves #1
1 parent 2505637 commit db3e2b4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/app/code/community/IntegerNet/Solr/Model/Bridge/LazyProductIterator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private static function getProductCollection($storeId, $productIdChunks, $chunkI
171171
Mage::dispatchEvent('integernet_solr_product_collection_load_after', array(
172172
'collection' => $productCollection
173173
));
174+
self::disconnectMysql();
174175

175176
return $productCollection;
176177
}
@@ -182,6 +183,7 @@ private function validInner()
182183
{
183184
$valid = $this->getInnerIterator()->valid();
184185
if (! $valid) {
186+
$this->disconnectMysql();
185187
call_user_func($this->_pageCallback, $this);
186188
}
187189
return $valid;
@@ -228,5 +230,19 @@ public function subset($ids)
228230
return $this->_bridgeFactory->createProductIterator($dataCollection);
229231
}
230232

233+
/**
234+
* Close all open MySQL connections (will be automatically reopened if used)
235+
*
236+
* Called during indexing to prevent wait timeout
237+
*/
238+
private static function disconnectMysql()
239+
{
240+
/** @var Zend_Db_Adapter_Abstract $connection */
241+
foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) {
242+
if ($connection instanceof Zend_Db_Adapter_Abstract) {
243+
$connection->closeConnection();
244+
}
245+
}
246+
}
231247

232248
}

0 commit comments

Comments
 (0)