0

I have a Magento2.3.5 Version but that store is causing a strange issue Store is really fast when just Reindex is runned but after 2 or maybe 3 hrs it became really slow and I have to run Reindex again. So to Trace that issue I've checked System.log file which was showing
[2024-06-28 11:12:46] main.CRITICAL: Item (Magento\Catalog\Model\Product\Interceptor) with the same ID "881" already exists. [] []
so for that I've created a plugin which code is

di.xml

<?xml version="1.0"?>
 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <type name="Magento\Eav\Model\Entity\Collection\AbstractCollection">
    <plugin name="find_duplicate_entry" type="Treezee\DuplicateEntry\plugin\Collection" sortOrder="20"/>
 </type>
</config>

while the plugin code is

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 */
namespace Treezee\DuplicateEntry\plugin;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Option\ArrayInterface;
 
class Collection
{
    /**
     * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $subject
     * @param \Closure $process
     * @param \Magento\Framework\DataObject $dataObject
     * @return $this
     */
    public function aroundAddItem(\Magento\Eav\Model\Entity\Collection\AbstractCollection $subject, \Closure $process, \Magento\Framework\DataObject $dataObject)
    {
        try{
            return $process($dataObject);
        }catch ( \Exception $e){
            return $this;
        }
    }
}

now this code fixes the above issue but still the Store Reindex issue was there so now when I looked at the System.log file the it shows enter image description here Now I dont know why this issue is happening or it is related to speed issue or not and how to fix that.. any help would be really appreciated Thanks.

3
  • Sorry but I can't figure how reindexing every x time would affect to frontend performance, unless you are using "update on save" mode, which you should avoid Commented Jul 2 at 6:56
  • exactly @RaulSanchez that is what I'm trying to figure out.. when I reindex the speed of store boost too much but with the passage of time it become slower and slower
    – Asad Khan
    Commented Jul 2 at 8:30
  • Looks like more a cache issue for me... If you are using files for cache. Have you checked var/cache size at 1 hour, 2 and 3? Commented Jul 2 at 17:14

1 Answer 1

0

Please Drop the catalog_category_product_index and catalog_category_product_index_tmp table and Be sure to take the backup before deleting. and then you can use the partial index on your site.

Magento provide two ways :

  • Update on Save: The data is updated when changes are saved.
  • Update by Schedule: The changed data is updated according to the schedule.

You can simply set the index on update on save instead on running all indexes.

Then it will helps solve your problem

enter image description here

5
  • above both tables are already empty but catalog_category_product_index_store1 table does have data do I need to truncate this one?
    – Asad Khan
    Commented Jul 2 at 9:08
  • No, no need of that. Can you share the screenshot of what you get while running indexer command now ? Commented Jul 2 at 10:02
  • it works perfectly fine I mean it is successful
    – Asad Khan
    Commented Jul 2 at 10:41
  • the main problem is that I have to run reindex every two or maybe 3 hours to speed up the store else it became so slow
    – Asad Khan
    Commented Jul 2 at 10:41
  • the only issue which I traced in the System.log file data else there is nothing in logs or anywhere
    – Asad Khan
    Commented Jul 2 at 10:44

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.