From eee9e6f40d48dc90df42a23819f10aedc8d692bc Mon Sep 17 00:00:00 2001 From: dMetzger Date: Wed, 26 Sep 2012 17:52:27 +0000 Subject: [PATCH] // Back office optimization begun (memory & SQL) and will resume tomorrow --- classes/controller/AdminController.php | 23 ++- .../admin/AdminAddressesController.php | 1 + controllers/admin/AdminCartsController.php | 2 +- .../admin/AdminCategoriesController.php | 3 +- .../admin/AdminCountriesController.php | 1 + .../admin/AdminCustomersController.php | 18 +- controllers/admin/AdminMetaController.php | 1 + controllers/admin/AdminOrdersController.php | 4 +- controllers/admin/AdminProductsController.php | 158 +++++++++--------- 9 files changed, 119 insertions(+), 92 deletions(-) diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 8925fa24b..54dfcb390 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -189,6 +189,9 @@ class AdminControllerCore extends Controller * @var array ids of the rows selected */ protected $boxes; + + /** @var string Do not automatically select * anymore but select only what is necessary */ + protected $explicitSelect = false; /** @var string Add fields into data query to display list */ protected $_select; @@ -2063,8 +2066,24 @@ class AdminControllerCore extends Controller $this->_listsql = ' SELECT SQL_CALC_FOUND_ROWS - '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').' - '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$select_shop.' + '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : ''); + + if ($this->explicitSelect) + { + foreach ($this->fields_list as $key => $array_value) + if (isset($array_value['filter_key'])) + $this->_listsql .= str_replace('!', '.', $array_value['filter_key']).','; + elseif ($key == 'id_'.$this->table) + $this->_listsql .= 'a.`'.bqSQL($key).'`,'; + elseif ($key != 'image' && !preg_match('/'.preg_quote($key, '/').'/i', $this->_select)) + $this->_listsql .= '`'.bqSQL($key).'`,'; + $this->_listsql = rtrim($this->_listsql, ','); + } + else + $this->_listsql .= ($this->lang ? 'b.*,' : '').' a.*'; + + $this->_listsql .= ' + '.(isset($this->_select) ? ', '.$this->_select : '').$select_shop.' FROM `'._DB_PREFIX_.$sql_table.'` a '.$lang_join.' '.(isset($this->_join) ? $this->_join.' ' : '').' diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index a4ca54a9a..24f883f3b 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -38,6 +38,7 @@ class AdminAddressesControllerCore extends AdminController $this->className = 'Address'; $this->lang = false; $this->addressType = 'customer'; + $this->explicitSelect = true; $this->context = Context::getContext(); $this->addRowAction('edit'); diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2efd96453..22c0a9eca 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -32,6 +32,7 @@ class AdminCartsControllerCore extends AdminController $this->table = 'cart'; $this->className = 'Cart'; $this->lang = false; + $this->explicitSelect = true; $this->addRowAction('view'); $this->addRowAction('delete'); @@ -87,7 +88,6 @@ class AdminCartsControllerCore extends AdminController 'width' => 40, 'align' => 'center', 'type' => 'bool', - 'filter_key' => 'id_guest', 'havingFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'tab-customers.gif') ) diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 4ccbee68d..167413b1c 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -45,6 +45,7 @@ class AdminCategoriesControllerCore extends AdminController $this->className = 'Category'; $this->lang = true; $this->deleted = false; + $this->explicitSelect = true; $this->context = Context::getContext(); @@ -73,7 +74,7 @@ class AdminCategoriesControllerCore extends AdminController 'position' => array( 'title' => $this->l('Position'), 'width' => 40, - 'filter_key' => 'cs!position', + 'filter_key' => 'sa!position', 'align' => 'center', 'position' => 'position' ), diff --git a/controllers/admin/AdminCountriesController.php b/controllers/admin/AdminCountriesController.php index 400f517c7..b4d002e48 100644 --- a/controllers/admin/AdminCountriesController.php +++ b/controllers/admin/AdminCountriesController.php @@ -34,6 +34,7 @@ class AdminCountriesControllerCore extends AdminController $this->lang = true; $this->deleted = false; + $this->explicitSelect = true; $this->addRowAction('edit'); $this->context = Context::getContext(); diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 427d60345..7bdc09433 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -41,6 +41,7 @@ class AdminCustomersControllerCore extends AdminController $this->className = 'Customer'; $this->lang = false; $this->deleted = true; + $this->explicitSelect = true; $this->addRowAction('edit'); $this->addRowAction('view'); @@ -63,6 +64,15 @@ class AdminCustomersControllerCore extends AdminController $genders[$gender->id] = $gender->name; } + $this->_select = ' + a.date_add, + IF (YEAR(`birthday`) = 0, "-", (YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5))) AS `age`, ( + SELECT c.date_add FROM '._DB_PREFIX_.'guest g + LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest + WHERE g.id_customer = a.id_customer + ORDER BY c.date_add DESC + LIMIT 1 + ) as connect'; $this->fields_list = array( 'id_customer' => array( 'title' => $this->l('ID'), @@ -212,14 +222,6 @@ class AdminCustomersControllerCore extends AdminController public function renderList() { - $this->_select = 'IF (YEAR(`birthday`) = 0, "-", (YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5))) AS `age`, ( - SELECT c.date_add FROM '._DB_PREFIX_.'guest g - LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest - WHERE g.id_customer = a.id_customer - ORDER BY c.date_add DESC - LIMIT 1 - ) as connect'; - if (Tools::isSubmit('submitBulkdelete'.$this->table) || Tools::isSubmit('delete'.$this->table)) $this->tpl_list_vars = array( 'delete_customer' => true, diff --git a/controllers/admin/AdminMetaController.php b/controllers/admin/AdminMetaController.php index a7380e906..7154ddab2 100644 --- a/controllers/admin/AdminMetaController.php +++ b/controllers/admin/AdminMetaController.php @@ -41,6 +41,7 @@ class AdminMetaControllerCore extends AdminController $this->sm_file = _PS_ROOT_DIR_.'/sitemap.xml'; $this->rb_data = $this->getRobotsContent(); + $this->explicitSelect = true; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index e5abef902..0ec08dae3 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -35,11 +35,13 @@ class AdminOrdersControllerCore extends AdminController $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); + $this->explicitSelect = true; $this->deleted = false; $this->context = Context::getContext(); $this->_select = ' + a.id_currency, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, @@ -77,7 +79,6 @@ class AdminOrdersControllerCore extends AdminController 'width' => 25, 'align' => 'center', 'type' => 'bool', - 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array( 0 => 'blank.gif', @@ -90,7 +91,6 @@ class AdminOrdersControllerCore extends AdminController ), 'customer' => array( 'title' => $this->l('Customer'), - 'filter_key' => 'customer', 'tmpTableFilter' => true ), 'total_paid_tax_incl' => array( diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 11a5d92a3..a4241b04e 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -60,6 +60,7 @@ class AdminProductsControllerCore extends AdminController $this->table = 'product'; $this->className = 'Product'; $this->lang = true; + $this->explicitSelect = true; $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); if (!Tools::getValue('id_product')) @@ -72,84 +73,6 @@ class AdminProductsControllerCore extends AdminController $this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000); $this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'); - $this->fields_list = array(); - $this->fields_list['id_product'] = array( - 'title' => $this->l('ID'), - 'align' => 'center', - 'width' => 20 - ); - $this->fields_list['image'] = array( - 'title' => $this->l('Photo'), - 'align' => 'center', - 'image' => 'p', - 'width' => 70, - 'orderby' => false, - 'filter' => false, - 'search' => false - ); - $this->fields_list['name'] = array( - 'title' => $this->l('Name'), - 'filter_key' => 'b!name' - ); - $this->fields_list['reference'] = array( - 'title' => $this->l('Reference'), - 'align' => 'left', - 'width' => 80 - ); - if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) - $this->fields_list['shopname'] = array( - 'title' => $this->l('Default Shop'), - 'width' => 230, - 'filter_key' => 'shop!name', - ); - else - $this->fields_list['name_category'] = array( - 'title' => $this->l('Category'), - 'width' => 230, - 'filter_key' => 'cl!name', - ); - $this->fields_list['price'] = array( - 'title' => $this->l('Base price'), - 'width' => 90, - 'type' => 'price', - 'align' => 'right', - 'filter_key' => 'a!price' - ); - $this->fields_list['price_final'] = array( - 'title' => $this->l('Final price'), - 'width' => 90, - 'type' => 'price', - 'align' => 'right', - 'havingFilter' => true, - 'orderby' => false - ); - $this->fields_list['sav_quantity'] = array( - 'title' => $this->l('Quantity'), - 'width' => 90, - 'align' => 'right', - 'filter_key' => 'sav!quantity', - 'orderby' => true, - 'hint' => $this->l('This is the quantity available in the current shop/group'), - ); - $this->fields_list['active'] = array( - 'title' => $this->l('Displayed'), - 'width' => 70, - 'active' => 'status', - 'filter_key' => 'sa!active', - 'align' => 'center', - 'type' => 'bool', - 'orderby' => false - ); - if ((int)Tools::getValue('id_category')) - $this->fields_list['position'] = array( - 'title' => $this->l('Position'), - 'width' => 70, - 'filter_key' => 'cp!position', - 'align' => 'center', - 'position' => 'position' - ); - - // @since 1.5 : translations for tabs $this->available_tabs_lang = array ( 'Informations' => $this->l('Information'), @@ -250,7 +173,86 @@ class AdminProductsControllerCore extends AdminController $this->_where .= ' AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))'; else $this->_where .= ' AND (i.cover=1 OR i.id_image IS NULL)'; + + $this->fields_list = array(); + $this->fields_list['id_product'] = array( + 'title' => $this->l('ID'), + 'align' => 'center', + 'width' => 20 + ); + $this->fields_list['image'] = array( + 'title' => $this->l('Photo'), + 'align' => 'center', + 'image' => 'p', + 'width' => 70, + 'orderby' => false, + 'filter' => false, + 'search' => false + ); + $this->fields_list['name'] = array( + 'title' => $this->l('Name'), + 'filter_key' => 'b!name' + ); + $this->fields_list['reference'] = array( + 'title' => $this->l('Reference'), + 'align' => 'left', + 'width' => 80 + ); + + if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) + $this->fields_list['shopname'] = array( + 'title' => $this->l('Default Shop'), + 'width' => 230, + 'filter_key' => 'shop!name', + ); + else + $this->fields_list['name_category'] = array( + 'title' => $this->l('Category'), + 'width' => 230, + 'filter_key' => 'cl!name', + ); + $this->fields_list['price'] = array( + 'title' => $this->l('Base price'), + 'width' => 90, + 'type' => 'price', + 'align' => 'right', + 'filter_key' => 'a!price' + ); + $this->fields_list['price_final'] = array( + 'title' => $this->l('Final price'), + 'width' => 90, + 'type' => 'price', + 'align' => 'right', + 'havingFilter' => true, + 'orderby' => false + ); + $this->fields_list['sav_quantity'] = array( + 'title' => $this->l('Quantity'), + 'width' => 90, + 'align' => 'right', + 'filter_key' => 'sav!quantity', + 'orderby' => true, + 'hint' => $this->l('This is the quantity available in the current shop/group'), + ); + $this->fields_list['active'] = array( + 'title' => $this->l('Displayed'), + 'width' => 70, + 'active' => 'status', + 'filter_key' => $alias.'!active', + 'align' => 'center', + 'type' => 'bool', + 'orderby' => false + ); + if ((int)Tools::getValue('id_category')) + $this->fields_list['position'] = array( + 'title' => $this->l('Position'), + 'width' => 70, + 'filter_key' => 'cp!position', + 'align' => 'center', + 'position' => 'position' + ); } + protected function _cleanMetaKeywords($keywords) { if (!empty($keywords) && $keywords != '')