Skip to content

Commit

Permalink
Added new perfomance setting: chunk_size (500 by default)
Browse files Browse the repository at this point in the history
It can be used when mysql 'max_allowed_packet' size is too small
and you need to decrease query size, or it can be increased to
decrease queries count during cronjob.
  • Loading branch information
vovayatsyuk committed Apr 7, 2015
1 parent aad982a commit b94c0f6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/code/community/Yavva/Alsoviewed/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function processLog()
$data = $log->getGroupedRelations();
if ($data) {
try {
Mage::getResourceModel('alsoviewed/relation')->updateRelations($data);
$size = Mage::getStoreConfig('alsoviewed/perfomance/chunk_size');
$model = Mage::getResourceModel('alsoviewed/relation');
foreach (array_chunk($data, $size) as $_data) {
$model->updateRelations($_data);
}
$log->clean();
} catch (Zend_Db_Exception $e) {
Mage::logException($e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ public function processAction()
$data = $log->getGroupedRelations();
if ($data) {
try {
$result = Mage::getResourceModel('alsoviewed/relation')->updateRelations($data);
$size = Mage::getStoreConfig('alsoviewed/perfomance/chunk_size');
$model = Mage::getResourceModel('alsoviewed/relation');
foreach (array_chunk($data, $size) as $_data) {
$model->updateRelations($_data);
}
$log->clean();
$this->_getSession()->addSuccess(
Mage::helper('adminhtml')->__('Total of %d record(s) have been updated.', $result)
Mage::helper('adminhtml')->__('Total of %d record(s) have been updated.', count($data))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
Expand Down
3 changes: 3 additions & 0 deletions app/code/community/Yavva/Alsoviewed/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<image_width>170</image_width>
<image_height>170</image_height>
</right>
<perfomance>
<chunk_size>500</chunk_size>
</perfomance>
</alsoviewed>
</default>
</config>
18 changes: 18 additions & 0 deletions app/code/community/Yavva/Alsoviewed/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@
</image_height>
</fields>
</right>
<perfomance>
<label>Perfomance</label>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<chunk_size translate="label comment">
<label>Relations count to process per one query</label>
<comment>You may need to decrease this value, if you found the "Got a packet bigger than 'max_allowed_packet' bytes" error in log</comment>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</chunk_size>
</fields>
</perfomance>
</groups>
</alsoviewed>
</sections>
Expand Down
3 changes: 3 additions & 0 deletions app/locale/en_US/Yavva_Alsoviewed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
"Also Viewed Recommendations","Also Viewed Recommendations"
"Build Recommendations on","Build Recommendations on"
"Current Product","Current Product"
"Perfomance","Perfomance"
"Relations count to process per one query","Relations count to process per one query"
"You may need to decrease this value, if you found the ""Got a packet bigger than 'max_allowed_packet' bytes"" error in log","You may need to decrease this value, if you found the ""Got a packet bigger than 'max_allowed_packet' bytes"" error in log"

0 comments on commit b94c0f6

Please sign in to comment.