From: Banana Date: Fri, 1 Jan 2021 16:14:03 +0000 (+0100) Subject: query debug in gorenest. Also reduced to one query there X-Git-Tag: 1.0~27 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=cb124e5f088adc45357882b55b0df87b06b2b998;p=bibliotheca-php.git query debug in gorenest. Also reduced to one query there --- diff --git a/webclient/index.php b/webclient/index.php index df986ab..1af3a24 100644 --- a/webclient/index.php +++ b/webclient/index.php @@ -63,6 +63,7 @@ $DB->query("SET collation_connection = 'utf8mb4_unicode_ci'"); $Doomguy = new Doomguy($DB); # menu Object $Gorenest = new GoreNest($DB,$Doomguy); +$Gorenest->loadMenu(); $_requestMode = false; if(isset($_GET['p']) && !empty($_GET['p'])) { diff --git a/webclient/lib/gorenest.class.php b/webclient/lib/gorenest.class.php index 08fbb42..dee1e20 100644 --- a/webclient/lib/gorenest.class.php +++ b/webclient/lib/gorenest.class.php @@ -43,6 +43,13 @@ class GoreNest { */ private $_menuData = array(); + /** + * Array for faster check which call is allowed + * + * @var array + */ + private $_allowedPageRequests = array(); + /** * GoreNest constructor. * @@ -55,67 +62,60 @@ class GoreNest { } /** - * Get the menu data for given area and category. - * This shows only entries which have a category set. - * No category can be used for hidden entries. + * Load the complete menu * - * @param string $category - * @param bool $reload - * @return array + * @return void */ - public function get($category,$reload=false) { - - if(empty($category)) return false; - - if(empty($reload) && isset($this->_menuData[$category])) { - return $this->_menuData[$category]; - } - + public function loadMenu() { # reset the menu - $this->_menuData[$category] = array(); + $this->_menuData = array(); $queryStr = "SELECT id, text, action, icon, category FROM `".DB_PREFIX."_menu` - WHERE ".$this->_User->getSQLRightsString()." - AND `category` = '".$this->_DB->real_escape_string($category)."' + WHERE ".$this->_User->getSQLRightsString()." ORDER BY position"; + if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true)); try { $query = $this->_DB->query($queryStr); if($query !== false && $query->num_rows > 0) { while(($result = $query->fetch_assoc()) != false) { $this->_menuData[$result['category']][$result['id']] = $result; + $this->_allowedPageRequests[$result['action']] = $result['action']; } } } catch (Exception $e) { error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); } + } + + /** + * Get the menu data for given area and category. + * This shows only entries which have a category set. + * No category can be used for hidden entries. + * + * @param string $category + * @param bool $reload + * @return array + */ + public function get($category,$reload=false) { + + if(empty($category)) return false; + + if(empty($reload) && isset($this->_menuData[$category])) { + return $this->_menuData[$category]; + } + $this->loadMenu($reload); return $this->_menuData[$category]; } /** - * Allowed page requests based on the menu entries and user + * Return allowed page requests * * @return array */ public function allowedPageRequests() { - $ret = array(); - $queryStr = "SELECT id, action - FROM `".DB_PREFIX."_menu` - WHERE ".$this->_User->getSQLRightsString().""; - try { - $query = $this->_DB->query($queryStr); - if($query !== false && $query->num_rows > 0) { - while(($result = $query->fetch_assoc()) != false) { - $ret[$result['action']] = $result['action']; - } - } - } - catch (Exception $e) { - error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); - } - - return $ret; + return $this->_allowedPageRequests; } }