]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
query debug in gorenest. Also reduced to one query there
authorBanana <mail@bananas-playground.net>
Fri, 1 Jan 2021 16:14:03 +0000 (17:14 +0100)
committerBanana <mail@bananas-playground.net>
Fri, 1 Jan 2021 16:14:03 +0000 (17:14 +0100)
webclient/index.php
webclient/lib/gorenest.class.php

index df986abeaeba293672becf399f414b8537267f16..1af3a240e1c94a01a7bd1667d00aeeaa99c577b0 100644 (file)
@@ -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'])) {
index 08fbb42f5263814758db4d6497fbede453cd0280..dee1e20a9838f96f0b62f4e316f4dc5acaee786d 100644 (file)
@@ -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;
        }
 }