Magento comes with a log-cleaning process as a Magento shell script located at
shell/log.php, which is also used in the log maintenance configurable in the admin.
I traced the code to
Mage_Log_Model_Resource_Log for the piece responsible for cleaning when
php -f log.php clean --days xxx is executed. I'm running it manually, and I'm seeing
report_viewed_product_index being cleaned as well, even though I don't see any reference to them in the code. Any ideas?
I was able to
SHOW CREATE TABLE, which shows me everything I need to know.
CREATE TABLE `report_viewed_product_index` ( `index_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Index Id', `visitor_id` int(10) unsigned DEFAULT NULL COMMENT 'Visitor Id', `customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id', `product_id` int(10) unsigned NOT NULL COMMENT 'Product Id', `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id', `added_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Added At', PRIMARY KEY (`index_id`), UNIQUE KEY `UNQ_REPORT_VIEWED_PRODUCT_INDEX_VISITOR_ID_PRODUCT_ID` (`visitor_id`,`product_id`), UNIQUE KEY `UNQ_REPORT_VIEWED_PRODUCT_INDEX_CUSTOMER_ID_PRODUCT_ID` (`customer_id`,`product_id`), KEY `IDX_REPORT_VIEWED_PRODUCT_INDEX_STORE_ID` (`store_id`), KEY `IDX_REPORT_VIEWED_PRODUCT_INDEX_ADDED_AT` (`added_at`), KEY `IDX_REPORT_VIEWED_PRODUCT_INDEX_PRODUCT_ID` (`product_id`), CONSTRAINT `FK_REPORT_VIEWED_PRD_IDX_CSTR_ID_CSTR_ENTT_ENTT_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_REPORT_VIEWED_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_REPORT_VIEWED_PRODUCT_INDEX_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=11096 DEFAULT CHARSET=utf8 COMMENT='Reports Viewed Product Index Table'