From c5c863c9c445152cf8fd91603a83e35eeff72f6e Mon Sep 17 00:00:00 2001 From: Banana Date: Thu, 3 Oct 2019 21:34:43 +0200 Subject: [PATCH] reduce some load. updated todo --- TODO | 2 +- webroot/lib/link.class.php | 36 ++++++++++++++++++++++++++++++++ webroot/lib/management.class.php | 12 +++++++---- webroot/view/overview.php | 2 +- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 8dfa880..e9f37a2 100755 --- a/TODO +++ b/TODO @@ -3,7 +3,7 @@ TODO / Feature list + theme support + bookmark js snippet + snapshots -+ stats ++ stats, storage usage + private links + more "secure" user authentication ++ multiple user accounts and stuff diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index f3d2419..09130a6 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -79,6 +79,42 @@ class Link { return $this->_data; } + /** + * loads only the info needed to display the link + * for edit use $this->load + * @param $hash + * @return array + */ + public function loadShortInfo($hash) { + $this->_data = array(); + + if(!empty($hash)) { + $queryStr = "SELECT + any_value(`id`) as id, + any_value(`link`) as link, + any_value(`description`) as description, + any_value(`title`) as title, + any_value(`image`) as image, + any_value(`hash`) as hash + FROM `".DB_PREFIX."_link` + WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; + $query = $this->DB->query($queryStr); + if(!empty($query) && $query->num_rows == 1) { + $this->_data = $query->fetch_assoc(); + + # add stuff + $this->_image(); + } + } + + return $this->_data; + } + + /** + * return all or data fpr given key on the current loaded link + * @param bool $key + * @return array|mixed + */ public function getData($key=false) { $ret = $this->_data; diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index a26cab7..e709974 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -265,15 +265,15 @@ class Management { /** * return all links and Info we have from the combined view * @param bool | int $limit + * @param bool $offset * @return array */ public function links($limit=false,$offset=false) { $ret = array(); - $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES." - FROM `".DB_PREFIX."_combined` + $queryStr = "SELECT `hash` + FROM `".DB_PREFIX."_link` WHERE `status` = 2 - GROUP BY `hash` ORDER BY `created` DESC"; if(!empty($limit)) { $queryStr .= " LIMIT $limit"; @@ -283,7 +283,11 @@ class Management { } $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { - $ret['results'] = $query->fetch_all(MYSQLI_ASSOC); + while($result = $query->fetch_assoc()) { + $linkObj = new Link($this->DB); + $ret['results'][] = $linkObj->loadShortInfo($result['hash']); + unset($linkObj); + } $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS `amount` FROM `".DB_PREFIX."_combined` diff --git a/webroot/view/overview.php b/webroot/view/overview.php index fc5bc5c..c9dbc38 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -101,7 +101,7 @@
- + -- 2.39.5