5

Our magento store is writing about 50 rows per second to the report_viewed_product_index table.

How can I disable this event?

I have log cleaning cron enabled but that doesn't prevent the unnecessary DB writes.

Are there any downside to disabling this?

2
  • Right, this is waiting our SSD, the main cause that SEO crawlers are accessing constantly to the site (20/30+ access for second) and as you wrote this produce an high amount of write on the DB ( and so on the disk )
    – Fra
    Jan 19, 2018 at 3:41
  • A different approach would be disable this functionality only for the crawlers ...similar problem happens with the sessions, here some more infos magento.stackexchange.com/questions/119849/…
    – Fra
    Jan 19, 2018 at 3:42

3 Answers 3

10

The event is being fired from core. You can disable this event observer in a custom module (rather then editing core files, which is evil ;) ). Put this in your app/code/local/(VendorName)/(ModuleName)/etc/config.xml:

<config>
    <frontend>
        <events>
            <catalog_controller_product_view>
                <observers>
                    <reports>
                        <type>disabled</type>
                    </reports>
                </observers>
            </catalog_controller_product_view>
        </events>
    </frontend>
</config>

The magic happens in merging your config.xml with the one from core that is defining this observer. Your XML overrides the core <type> node and sets the type to "disabled" which results in the event observer still being there, but not being fired.

Is there any downside to this (disabling viewed products counting)?

I can't think of any downside in disabling this other than that you can't see product view reports anymore...

Also see the answer by Fra here explaining how to disable reports completely (if you don't need them at all) and other Magento code that puts a load on your database.

6
  • Very nice solution. Didn't know it.
    – zhartaunik
    Apr 10, 2015 at 12:11
  • This does not seem to be working. As with the other solution, it seems the only way I can get viewed product reports disabled is to edit the core file. Any clue as to why?
    – refueled
    Apr 10, 2015 at 12:13
  • Is the custom module configured right? It is enabled in app/etc/modules/(VendorName)_(ModuleName).xml? You could dump the event config of "catalog_controller_product_view" event inside the dispatchEvent() method in app/code/core/Mage/Core/Model/App.php. And there are a hundred things more you could check...
    – 7ochem
    Apr 10, 2015 at 12:18
  • Sorry, my fault. I had a typo. Everything appears to be working. Thank you!
    – refueled
    Apr 10, 2015 at 12:25
  • @Fra, I reversed your edit. First of all, I think it is a slightly different topic. Second, if you have anything to add, please post an answer yourself.
    – 7ochem
    Jan 22, 2018 at 8:42
3

Don't forget: magento strongly recommended do not edit core files.

The module which create reports is Mage_Reports. On one hand you can disable module, but I can't tell you what dangerous can happen. On the other hand magento create reports in Mage_Reports_Model_Observer. You can remove from the config unnecessary reports. Here is path to the config:

app/code/core/Mage/Reports/etc/config.xml

The most probably the event which are you looking for is:

        <catalog_controller_product_view>
            <observers>
                <reports>
                    <class>reports/event_observer</class>
                    <method>catalogProductView</method>
                </reports>
            </observers>
        </catalog_controller_product_view>

You can remove it.

4
  • Rather than editing /core/ I copied the file to /local/ and edited, but it doesn't seem to have done anything. I cleared magento cache and compiler is off.
    – refueled
    Apr 10, 2015 at 11:23
  • Firstly to be sure that everything is working - try to remove all children inside <events> tag inside core file. Then you can add this fix to local folder.
    – zhartaunik
    Apr 10, 2015 at 11:32
  • Editing the core file directly appears to work, however, the local file is still not working for some reason
    – refueled
    Apr 10, 2015 at 11:56
  • Most probably it didn't work because core config.xml was also merged with global config. And this part was also merged.
    – zhartaunik
    Apr 10, 2015 at 12:12
3

Product Page Report:

  1. Report can be disabled in the backend see Mage::helper('reports')->isReportsEnabled();
  2. or you can override Mage_Reports_Model_Event_Observer and add your logic to the method catalogProductView()

Visitor Log:
The above report is not the only one that write on DB, the visitor log is far more active ( 2 insert for every BOT access ).
So if your concern is to limit the MySql activity you should look into the below infos:

The following methods are called on every access:

  • Mage_Log_Model_Visitor:initByRequest()
  • Mage_Log_Model_Visitor:saveByRequest()

Apparently Magento developers were aware by the BOT risk:

As you can see there is a filter in the constructor that check the user agent:

 $ignoreAgents = $this->_config->getNode('global/ignore_user_agents');
        if ($ignoreAgents) {
            $ignoreAgents = $ignoreAgents->asArray();
            if (in_array($userAgent, $ignoreAgents)) {
                $this->_skipRequestLogging = true;
            }
        }

Anyway it filters only certain bot ...

 <global>
      ...
        <ignore_user_agents>
            <google1>Googlebot/1.0 ([email protected] http://googlebot.com/)</google1>
            <google2>Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)</google2>
            <google3>Googlebot/2.1 (+http://www.googlebot.com/bot.html)</google3>
        </ignore_user_agents>
1
  • 1
    nicely done +1. I'll reference your answer in mine, especially about disabling reports completely.
    – 7ochem
    Jan 22, 2018 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.