From 5a6728209a6f1f281637f4091d6bf845afeb13ab Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 Aug 2017 01:04:33 +0100 Subject: [PATCH 1/3] improve cache logging --- core/database.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index b63d3d1d..ec1a7ce2 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -405,7 +405,7 @@ class MemcachedCache implements CacheEngine { $res = $this->memcache->getResultCode(); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { - $hit = $res == Memcached::RES_SUCCESS ? "miss" : "hit"; + $hit = $res == Memcached::RES_SUCCESS ? "hit" : "miss"; file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND); } if($res == Memcached::RES_SUCCESS) { @@ -690,7 +690,7 @@ class Database { * @param string $sql */ private function count_execs($db, $sql, $inputarray) { - if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { $text = $sql." -- ".join(", ", $inputarray)."\n"; @@ -707,7 +707,7 @@ class Database { } private function count_time($method, $start) { - if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $text = $method.":".(microtime(true) - $start)."\n"; file_put_contents("data/sql.log", $text, FILE_APPEND); } From d875ab66a1d46225343ad395f05f3f93991dda72 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 Aug 2017 01:05:18 +0100 Subject: [PATCH 2/3] 60 second post-list cache --- ext/index/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/index/main.php b/ext/index/main.php index 49e53781..29d225ea 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -265,7 +265,7 @@ class Index extends Extension { $images = $database->cache->get("post-list:$page_number"); if(!$images) { $images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms); - $database->cache->set("post-list:$page_number", $images, 600); + $database->cache->set("post-list:$page_number", $images, 60); } } else { From 35bd51e5138bbd29adc7b365e62c63b043796192 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 Aug 2017 00:42:19 +0100 Subject: [PATCH 3/3] use 'count()' + result->get_one() to count images, rather than 'select *' + result->rowcount()... --- core/imageboard.pack.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 4975c050..0ee89a09 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -282,8 +282,7 @@ class Image { } else { $querylet = Image::build_search_querylet($tags); - $result = $database->execute($querylet->sql, $querylet->variables); - return $result->rowCount(); + return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); } }