Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

https://github.com/magesuite/index-invalidation-logger

The module logs index invalidations along with respective stacktrace in order to gain more knowledge about index invalidations that are triggered automatically.

Installation

This module is optional.

composer require "creativestyle/magesuite-index-invalidation-logger" ^1.0.0

Admin settings

In Stores -> Configuration -> Advanced -> System the following module’s settings can be found:

Index Invalidation Debugger Settings

Field

Optiona

Comment

Enable Logging

Yes/No 

Enables logging all index invalidation along with stacktraces.

Logging retention period

How long (in days) logs should be kept

The index logger link can be found in System -> Tools -> Index Management

Backend

AdminHtml - Index invalidation log action

vendor/creativestyle/magesuite-index-invalidation-logger/Controller/Adminhtml/Log/Index.php:7
class Index extends \Magento\Backend\App\Action
{
    public function execute()
    {
        $resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
        $resultPage->getConfig()->getTitle()->set(__('Index invalidation log'));

        return $resultPage;
    }
}

Cron - cleanup logs

vendor/creativestyle/magesuite-index-invalidation-logger/Cron/LogsCleanup.php:26

class LogsCleanup
{
    public function execute()
    {
        if (!$this->configuration->isLoggingEnabled()) {
            return;
        }

        $this->cleanLogs->execute($this->configuration->getLoggingRetentionPeriod());
    }
}

Command - cleanup logs

Is used by previous mentioned cron

vendor/creativestyle/magesuite-index-invalidation-logger/Model/Command/CleanLogs.php:17
class CleanLogs
{
    public function execute($retentionPeriodInDays) {
        .....

        $logsTable = $this->connection->getTableName('index_invalidation_log');

        $this->connection->delete(
            $logsTable,
            "executed_at < date_sub(CURDATE(), INTERVAL ".$retentionPeriodInDays." Day)"
        );
    }
}

Adding $stackTraceId to InvalidationLog table

vendor/creativestyle/magesuite-index-invalidation-logger/Model/ResourceModel/InvalidationLog.php:28
class InvalidationLog extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
    {
        $context = $object->getContext();
        $stackTrace = $context['stack_trace'];

        $stackTraceId = $this->stacktraceResourceModel->getStackTraceId($stackTrace);

        unset($context['stack_trace']);

        $object->setContext(json_encode($context));
        $object->setStacktraceId($stackTraceId);

        return parent::_beforeSave($object);
    }
}

vendor/creativestyle/magesuite-index-invalidation-logger/Model/ResourceModel/InvalidationLogStacktrace.php:14
class InvalidationLogStacktrace extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    public function getStackTraceId($stackTrace)
    {
        .....
        $stacktraceId = $this->getExistingStacktraceId($hash);
        .....
        $this->existingStackTracesIdsCache[$hash] = $stacktraceId;

        return $this->existingStackTracesIdsCache[$hash];
    }
}

Frontend

There are no frontend functionalities in the module.

  • No labels