Skip to content

Commit 611863c

Browse files
committed
5886: Close MySQL connection during category and cms indexing as well
1 parent db3e2b4 commit 611863c

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class IntegerNet_Solr_Model_Bridge_LazyCategoryIterator implements CategoryItera
4242
*/
4343
protected $_collectionIterator;
4444

45+
/**
46+
* @var IntegerNet_Solr_Model_Resource_Db
47+
*/
48+
protected $_dbResource;
49+
4550
/**
4651
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4752
* @return Iterator The inner iterator for the current entry.
@@ -63,6 +68,7 @@ public function __construct($_storeId, $_categoryIdFilter, $_categorySize)
6368
$this->_storeId = $_storeId;
6469
$this->_categoryIdFilter = $_categoryIdFilter;
6570
$this->_categorySize = $_categorySize;
71+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6672
}
6773

6874
/**
@@ -92,6 +98,7 @@ public function valid()
9298
} elseif ($this->_currentCategory < $this->_collection->getLastPageNumber()) {
9399
$this->_currentCategory++;
94100
$this->_collection = self::getCategoryCollection($this->_storeId, $this->_categoryIdFilter, $this->_categorySize, $this->_currentCategory);
101+
$this->_dbResource->disconnectMysql();
95102
$this->_collectionIterator = $this->_collection->getIterator();
96103
$this->getInnerIterator()->rewind();
97104
return $this->getInnerIterator()->valid();
@@ -106,6 +113,7 @@ public function rewind()
106113
{
107114
$this->_currentCategory = 1;
108115
$this->_collection = self::getCategoryCollection($this->_storeId, $this->_categoryIdFilter, $this->_categorySize, $this->_currentCategory);
116+
$this->_dbResource->disconnectMysql();
109117
$this->_collectionIterator = $this->_collection->getIterator();
110118
$this->_collectionIterator->rewind();
111119
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class IntegerNet_Solr_Model_Bridge_LazyPageIterator implements PageIterator, Out
4242
*/
4343
protected $_collectionIterator;
4444

45+
/**
46+
* @var IntegerNet_Solr_Model_Resource_Db
47+
*/
48+
protected $_dbResource;
49+
4550
/**
4651
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4752
* @return Iterator The inner iterator for the current entry.
@@ -63,6 +68,7 @@ public function __construct($_storeId, $_pageIdFilter, $_pageSize)
6368
$this->_storeId = $_storeId;
6469
$this->_pageIdFilter = $_pageIdFilter;
6570
$this->_pageSize = $_pageSize;
71+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6672
}
6773

6874
/**
@@ -92,6 +98,7 @@ public function valid()
9298
} elseif ($this->_currentPage < $this->_collection->getLastPageNumber()) {
9399
$this->_currentPage++;
94100
$this->_collection = self::getPageCollection($this->_storeId, $this->_pageIdFilter, $this->_pageSize, $this->_currentPage);
101+
$this->_dbResource->disconnectMysql();
95102
$this->_collectionIterator = $this->_collection->getIterator();
96103
$this->getInnerIterator()->rewind();
97104
return $this->getInnerIterator()->valid();
@@ -106,6 +113,7 @@ public function rewind()
106113
{
107114
$this->_currentPage = 1;
108115
$this->_collection = self::getPageCollection($this->_storeId, $this->_pageIdFilter, $this->_pageSize, $this->_currentPage);
116+
$this->_dbResource->disconnectMysql();
109117
$this->_collectionIterator = $this->_collection->getIterator();
110118
$this->_collectionIterator->rewind();
111119
}

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class IntegerNet_Solr_Model_Bridge_LazyProductIterator implements PagedProductIt
4343
*/
4444
protected $_collectionIterator;
4545

46+
/**
47+
* @var IntegerNet_Solr_Model_Resource_Db
48+
*/
49+
protected $_dbResource;
50+
4651
/**
4752
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4853
* @return Iterator The inner iterator for the current entry.
@@ -61,6 +66,7 @@ public function __construct($_storeId, ProductIdChunks $productIdChunks)
6166
$this->_bridgeFactory = Mage::getModel('integernet_solr/bridge_factory');
6267
$this->_storeId = $_storeId;
6368
$this->_productIdChunks = $productIdChunks;
69+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6470
}
6571

6672
/**
@@ -100,6 +106,7 @@ public function valid()
100106
} elseif ($this->_currentChunkId < sizeof($this->_productIdChunks) - 1) {
101107
$this->_currentChunkId++;
102108
$this->_collection = self::getProductCollection($this->_storeId, $this->_productIdChunks, $this->_currentChunkId);
109+
$this->_dbResource->disconnectMysql();
103110
$this->_collectionIterator = $this->_collection->getIterator();
104111
$this->getInnerIterator()->rewind();
105112
return $this->validInner();
@@ -114,6 +121,7 @@ public function rewind()
114121
{
115122
$this->_currentChunkId = 0;
116123
$this->_collection = self::getProductCollection($this->_storeId, $this->_productIdChunks, $this->_currentChunkId);
124+
$this->_dbResource->disconnectMysql();
117125
$this->_collectionIterator = $this->_collection->getIterator();
118126
$this->_collectionIterator->rewind();
119127
}
@@ -171,7 +179,6 @@ private static function getProductCollection($storeId, $productIdChunks, $chunkI
171179
Mage::dispatchEvent('integernet_solr_product_collection_load_after', array(
172180
'collection' => $productCollection
173181
));
174-
self::disconnectMysql();
175182

176183
return $productCollection;
177184
}
@@ -183,7 +190,7 @@ private function validInner()
183190
{
184191
$valid = $this->getInnerIterator()->valid();
185192
if (! $valid) {
186-
$this->disconnectMysql();
193+
$this->_dbResource->disconnectMysql();
187194
call_user_func($this->_pageCallback, $this);
188195
}
189196
return $valid;
@@ -230,19 +237,4 @@ public function subset($ids)
230237
return $this->_bridgeFactory->createProductIterator($dataCollection);
231238
}
232239

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-
}
247-
248240
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Fabian Schmengler <fs@integer-net.de>
9+
*/
10+
class IntegerNet_Solr_Model_Resource_Db
11+
{
12+
/**
13+
* Close all open MySQL connections (will be automatically reopened by Magento if used)
14+
*
15+
* Can be called during indexing to prevent wait timeout
16+
*/
17+
public function disconnectMysql()
18+
{
19+
/** @var Zend_Db_Adapter_Abstract $connection */
20+
foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) {
21+
if ($connection instanceof Zend_Db_Adapter_Abstract) {
22+
$connection->closeConnection();
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)