Perf: Speed enhancement. Reduce one request for each page call.

This commit is contained in:
Laurent Destailleur 2011-02-16 20:54:24 +00:00
parent 93ab9b1577
commit e00704c36d

View File

@ -430,6 +430,7 @@ class Menubase
* @param mainmenu Value for mainmenu that defined top menu * @param mainmenu Value for mainmenu that defined top menu
* @param menu_handler Name of menu_handler used (auguria, eldy...) * @param menu_handler Name of menu_handler used (auguria, eldy...)
* @return array Return array with menu entries for top menu * @return array Return array with menu entries for top menu
* TODO Mutualize menuTopCharger and menuLeftCharger
*/ */
function menuTopCharger($type_user, $mainmenu, $menu_handler) function menuTopCharger($type_user, $mainmenu, $menu_handler)
{ {
@ -542,6 +543,7 @@ class Menubase
global $langs, $user, $conf, $leftmenu; // To export to dol_eval function global $langs, $user, $conf, $leftmenu; // To export to dol_eval function
global $rights; // To export to dol_eval function global $rights; // To export to dol_eval function
$menutopid='';
$leftmenu=$myleftmenu; $leftmenu=$myleftmenu;
$this->newmenu = $newmenu; $this->newmenu = $newmenu;
@ -549,7 +551,7 @@ class Menubase
$tabMenu = array (); $tabMenu = array ();
$sql = "SELECT m.rowid, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; $sql = "SELECT m.rowid, m.type, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " WHERE m.menu_handler in('".$menu_handler."','all')"; $sql.= " WHERE m.menu_handler in('".$menu_handler."','all')";
$sql.= " AND m.entity = ".$conf->entity; $sql.= " AND m.entity = ".$conf->entity;
@ -572,6 +574,9 @@ class Menubase
//$objm = $this->db->fetch_object($resql); //$objm = $this->db->fetch_object($resql);
$menu = $this->db->fetch_array($resql); $menu = $this->db->fetch_array($resql);
// Detect if it's top menu line
if ($menu['type'] == 'top' && $menu['mainmenu'] == $mainmenu) $menutopid=$menu['rowid'];
// Define $chaine // Define $chaine
$chaine=""; $chaine="";
$title = $langs->trans($menu['titre']); $title = $langs->trans($menu['titre']);
@ -644,21 +649,23 @@ class Menubase
} }
// Get menutopid // Get menutopid
$menutopid=''; /*$sql = "SELECT m.rowid, m.titre, m.type";
$sql = "SELECT m.rowid, m.titre, m.type";
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m"; $sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
$sql.= " WHERE m.mainmenu = '".$mainmenu."'"; $sql.= " WHERE m.mainmenu = '".$mainmenu."'";
$sql.= " AND m.menu_handler in('".$menu_handler."','all')"; $sql.= " AND m.menu_handler in('".$menu_handler."','all')";
$sql.= " AND m.entity = ".$conf->entity; $sql.= " AND m.entity = ".$conf->entity;
if ($type_user == 0) $sql.= " AND m.usertype in (0,2)";
if ($type_user == 1) $sql.= " AND m.usertype in (1,2)";
$sql.= " AND type = 'top'"; $sql.= " AND type = 'top'";
dol_syslog("Menubase::menuLeftCharger sql=".$sql);
// It should have only one response // It should have only one response
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
$menutop = $this->db->fetch_object($resql); $menutop = $this->db->fetch_object($resql);
if ($menutop) $menutopid=$menutop->rowid; if ($menutop) $menutopid=$menutop->rowid;
$this->db->free($resql); $this->db->free($resql);
//print "menutopid=".$menutopid." sql=".$sql; //print "menutopid=".$menutopid." sql=".$sql;
*/
// Now edit this->newmenu to add entries in tabMenu that are in childs // Now edit this->newmenu to add entries in tabMenu that are in childs
$this->recur($tabMenu, $menutopid, 1); $this->recur($tabMenu, $menutopid, 1);