Magento – Is It OK to Truncate report_viewed_product_index?

enterprise-1.13MySQLperformance

I was reading through the list of tables that are ok to truncate (https://stackoverflow.com/questions/12205714/list-of-tables-to-safely-truncate-in-magento) and I didn't see

report_viewed_product_index

The table is huge and it takes a very long time to restore the database. Is it safe to truncate this data or at least remove the oldest data?

Best Answer

As far as I can see/know this table is included in the event log_log_clean_after.

If you look under the file app/code/core/Mage/Reports/etc/config.xml you will see the following snippet.

<events>
    <log_log_clean_after>
        <observers>
            <reports>
                <class>reports/event_observer</class>
                <method>eventClean</method>
            </reports>
        </observers>
    </log_log_clean_after>
</events>

This method simply cleans all the report events and then the product viewed and compared tables.

public function eventClean(Varien_Event_Observer $observer)
{
    /* @var $event Mage_Reports_Model_Event */
    $event = Mage::getModel('reports/event');
    $event->clean();

    Mage::getModel('reports/product_index_compared')->clean();
    Mage::getModel('reports/product_index_viewed')->clean();

    return $this;
}

If you make sure you have the logClean cron setup then the reports should also be cleaned up with it.

Related Topic