Jump to content

[SOLVED] Slow Performance When Customer Have a Lot of Orders


duredo

Recommended Posts

hi, I have reseller that have a lot of orders. the problem is when they login, it will get slower and slower.

my suspicious, because prestashop load all saved addresses. if my reseller have 1000 addresses, then it will load 1000 addresses.

I can see in view-source:
var prestashop = {"addresses": 

can we limit the var prestashop = {"addresses": just 100 or 200?
how to do this, I can edit code. but don't know how to.

thank you

Edited by dosbiner (see edit history)
Link to comment
Share on other sites

Hi,

Addresses are loaded in the FrontController class, getTemplateVarCustomer() method, more precisely $addresses = $this->context->customer->getSimpleAddresses();

You can go to the getSimpleAddresses() function, which you find in the Customer class, and put a limit of results on sql.

Link to comment
Share on other sites

thank you @Ress, I can't make it work with that. But you gave me the idea.

create file in /override/classes/Customer.php and add this code

<?php

class Customer extends CustomerCore
{
    public function getSimpleAddressSql($idAddress = null, $idLang = null)
    {
        if (null === $idLang) {
            $idLang = Context::getContext()->language->id;
        }
        $shareOrder = (bool) Context::getContext()->shop->getGroup()->share_order;

        $sql = 'SELECT DISTINCT
                      a.`id_address` AS `id`,
                      a.`alias`,
                      a.`firstname`,
                      a.`lastname`,
                      a.`company`,
                      a.`address1`,
                      a.`address2`,
                      a.`postcode`,
                      a.`city`,
                      a.`id_state`,
                      s.name AS state,
                      s.`iso_code` AS state_iso,
                      a.`id_country`,
                      cl.`name` AS country,
                      co.`iso_code` AS country_iso,
                      a.`other`,
                      a.`phone`,
                      a.`phone_mobile`,
                      a.`vat_number`,
                      a.`dni`
                    FROM `' . _DB_PREFIX_ . 'address` a
                    LEFT JOIN `' . _DB_PREFIX_ . 'country` co ON (a.`id_country` = co.`id_country`)
                    LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (co.`id_country` = cl.`id_country`)
                    LEFT JOIN `' . _DB_PREFIX_ . 'state` s ON (s.`id_state` = a.`id_state`)
                    ' . ($shareOrder ? '' : Shop::addSqlAssociation('country', 'co')) . '
                    WHERE
                        `id_lang` = ' . (int) $idLang . '
                        AND `id_customer` = ' . (int) $this->id . '
                        AND a.`deleted` = 0
                        AND a.`active` = 1
                        LIMIT 100'; #change the limit here

        if (null !== $idAddress) {
            $sql .= ' AND a.`id_address` = ' . (int) $idAddress;
        }

        return $sql;
    }
}

 

Edited by dosbiner (see edit history)
Link to comment
Share on other sites

  • duredo changed the title to [SOLVED] Slow Performance When Customer Have a Lot of Orders

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...