Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Magento's index_event table

I'm playing with improving performance during saving category and I found that once category is updated via Magenti API or backend then the following update query is called

SQL: UPDATE `index_event` SET `event_id` = ?, `type` = ?, `entity` = ?, `entity_pk` = ?, `created_at` = ?, `old_data` = ?, `new_data` = ? WHERE (event_id='13066')
BIND: Array
(
    [0] => 13066
    [1] => save
    [2] => catalog_category
    [3] => 2867
    [4] => 2011-09-22 13:50:54
    [5] => a:4:{s:30:"Mage_Catalog_Model_Indexer_Url";N;s:40:"Mage_Catalog_Model_Category_Indexer_Flat";N;s:43:"Mage_Catalog_Model_Category_Indexer_Product";N;s:41:"Mage_CatalogSearch_Model_Indexer_Fulltext";N;}
    [6] => a:11:{s:35:"cataloginventory_stock_match_result";b:0;s:34:"catalog_product_price_match_result";b:0;s:24:"catalog_url_match_result";b:1;s:30:"Mage_Catalog_Model_Indexer_Url";N;s:33:"catalog_product_flat_match_result";b:0;s:34:"catalog_category_flat_match_result";b:1;s:40:"Mage_Catalog_Model_Category_Indexer_Flat";N;s:37:"catalog_category_product_match_result";b:1;s:43:"Mage_Catalog_Model_Category_Indexer_Product";N;s:35:"catalogsearch_fulltext_match_result";b:1;s:41:"Mage_CatalogSearch_Model_Indexer_Fulltext";N;}

Can anyone tell me what does it mean and will happen? It looks like some indexing actions are pushed to a queue but when does it execute?

like image 272
Jaro Avatar asked Jun 20 '12 08:06

Jaro


1 Answers

Your assumption "It looks like some indexing actions are pushed to a queue" is correct.

To answer your question "but when does it execute?":

Some Magento models, like

Mage_Core_Model_Store
Mage_Catalog_Model_Product
Mage_Catalog_Model_Category
Mage_CatalogInventory_Model_Stock_Item
Mage_Tag_Model_Tag
Mage_Tag_Model_Tag_Relation

for example, queue index events. Mainly before deleting and/or after committing.

They do this by either calling the logEvent() or the processEntityAction() method of the Mage_Index_Model_Indexer class.

  • If they call logEvent() directly, an index event will only be queued. Reindexing will not even be tried.

  • If they call processEntityAction(), also an index event will be queued, but Magento will try to process this index event right after queueing.

There's also a third method Mage_Index_Model_Indexer::indexEvents() being called by some modules. The difference to the former two is, that indexEvents() does not queue any index event, but will only try to immediately reindex.

Note that any reindexing thru processEntityAction() and indexEvents() will only happen, if the process mode of the corresponding index type is Mage_Index_Model_Process::MODE_REAL_TIME.

You can check this via System -> Index Management. If the Mode column reads Update on save, than that index is set to MODE_REAL_TIME.

If it reads Manual Update instead, it's set to Mage_Index_Model_Process::MODE_MANUAL, which means automatic reindexing will never happen at all.

In the latter case you need to manually trigger the reindexing processes to get your data reindexed. That can be achieved using several methods, e.g. by using System -> Index Management -> Index -> Reindex data -> Submit, or using the Magento shell/indexer.php on the command line, or by scripting your own indexer process collection handling started by a cron job.

like image 151
Jürgen Thelen Avatar answered Oct 06 '22 00:10

Jürgen Thelen