Slowness when changing product category and MySQL error



  • When I edit products, it takes a lot to save the modifications if I change the category. Sometimes I even get this error:

    Link to database cannot be established: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")
    
    

    This only happens when editing older products, but newer ones update fast.

    I’m using TB 1.0.7 migrated from PS 1.6.1.21

    Any idea of what can cause this?



  • Enable debug profiling, and then try again. Now you can check what makes it slow in the bottom page.



  • I’ve enabled debug profiling and I’ve got all these messages:

    Warning on line 265 in file /home/xxx/public_html/classes/PageCache.php
    [2] Invalid argument supplied for foreach()

    Unknown error on line 280 in file /home/xxx/public_html/modules/googleshopping/lib/phpseclib/Crypt/RSA.php
    [8192] Methods with the same name as their class will not be constructors in a future version of PHP; Crypt_RSA has a deprecated constructor

    Unknown error on line 82 in file /home/xxx/public_html/modules/googleshopping/lib/phpseclib/Crypt/Hash.php
    [8192] Methods with the same name as their class will not be constructors in a future version of PHP; Crypt_Hash has a deprecated constructor

    Unknown error on line 176 in file /home/xxx/public_html/modules/googleshopping/lib/phpseclib/Math/BigInteger.php
    [8192] Methods with the same name as their class will not be constructors in a future version of PHP; Math_BigInteger has a deprecated constructor

    Unknown error on line 115 in file /home/xxx/public_html/modules/shopgate/vendors/shopgate_library/vendors/JSON.php
    [8192] Methods with the same name as their class will not be constructors in a future version of PHP; sgServicesJSON has a deprecated constructor

    Unknown error on line 796 in file /home/xxx/public_html/modules/shopgate/vendors/shopgate_library/vendors/JSON.php
    [8192] Methods with the same name as their class will not be constructors in a future version of PHP; sgServicesJSON_Error has a deprecated constructor

    I’ve deleted Google Shopping and Shopgate modules because they were not installed and I was not using them.

    After deleting those modules, I only get the first warnig:

    Warning on line 265 in file /home/xxx/public_html/classes/PageCache.php
    [2] Invalid argument supplied for foreach()



  • This warning has nothing to do with the slowness. You have probably enabled debug mode, not profiling. Enable profiling, and then look at the bottom of the page for performance statistics

    0_1540468606619_7ad308d2-87c3-4bb7-b414-d221e7ad6506-image.png

    That should give you the basic idea what’s slow in your system

    0_1540468684968_f4f909b4-258d-416d-bff3-f927331ea186-image.png



  • @datakick

    Sorry, it was debug, you’re right. This is the profiling result:

    0_1540469247761_profiling.png



  • @cprats I don’t see anything. Is this a result of a product save operation?



  • @datakick said in Slowness when changing product category and MySQL error:

    @cprats I don’t see anything. Is this a result of a product save operation?

    Yes. The slowness only occurs with the products that were already in the store before the migration. After the change of category of those products, another change is fast as it should be.



  • Use debug profiling when you edit/save old products, there must be show the problem



  • @datakick
    I tried again and now I’ve got one of the slow products. It only happens if I change all categories. For example, a product in Categories-New-Covers will not experience a slow modification if changed to Categories-New. But, If I unselect all categories and I select a different category (for example, Sold Idems) saving process will be extremely slow. Here a screenshot of profiling while editing one of these products:

    0_1540566278493_debugparameters.jpg



  • @cprats we are getting closer. There are over 9000 sql queries – that’s way too many. Normally you shouldn’t see more than 300. I bet there’s some very inefficient loop that’s executing some query over and over.

    Please look at the bottom part of the profile stats, and search for section with sql statements named Doubles. It looks something like this (the red number says how many time was this sql executed)

    0_1540572494933_07d8dbbb-7985-4a8f-962e-810239291a27-image.png



  • @datakick Here is the Doubles section in 6 screenshots:

    0_1540573194524_doubles1.jpg
    0_1540573201043_doubles2.jpg
    0_1540573207293_doubles3.jpg
    0_1540573213420_doubles4.jpg
    0_1540573220756_doubles5.jpg
    0_1540573226699_doubles6.jpg



  • It seems the problem is with id_product. I am using this route to products in schema_urls: {categories:/}{rewrite} instead of the configuration I had when the core was Prestashop: {category:/}{id}-{rewrite}{-:ean13}.html



  • There is indeed very inefficient piece of code in classes/Product.php, function cleanPositions. When you remove product from a category, all products that are associated with that category and have higher position gets updated. In your case this leads to thousands of sql updates. They are very fast, but it adds up.

    That’s also the reason why you experience this problem only with olded products – they have lower positions inside categories. New products have higher position, so the total number of updates is much lower.

    I’ll prepare a fix and push it to thirtybees 1.0.8. Meanwhile, this is what you can do to avoid this problem:

    edit file classes/Product.php, find function cleanPositions, and remove these lines.



  • @datakick Thank-you so much for your help



  • I’ve removed the code you pointed out and now it works fine. Thanks again.


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.