From 6e914ff4e75a3a0d9acfab12a80551c1d8de3429 Mon Sep 17 00:00:00 2001
From: Shish <shish@shishnet.org>
Date: Thu, 21 Sep 2017 05:25:45 +0100
Subject: [PATCH 1/2] use just hash for flexihash lookup

---
 core/imageboard.pack.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index 0ee89a09..cc9c131f 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -781,7 +781,8 @@ class Image {
 				}
 			}
 
-			$choice = $flexihash->lookup($pre.$post);
+			// $choice = $flexihash->lookup($pre.$post);
+			$choice = $flexihash->lookup($this->hash);  // doesn't change
 			$tmpl = $pre.$choice.$post;
 		}
 

From 6aa704d04c585780bf43d2c4fa136d8b811b3f27 Mon Sep 17 00:00:00 2001
From: Shish <shish@shishnet.org>
Date: Thu, 21 Sep 2017 05:49:10 +0100
Subject: [PATCH 2/2] better image counting

---
 core/imageboard.pack.php | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index c7391358..7015a3c9 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -232,20 +232,21 @@ class Image {
 		if($tag_count === 0) {
 			$total = $database->cache->get("image-count");
 			if(!$total) {
-				$total = $database->get_one("SELECT COUNT(*) FROM images") || 0;
+				$total = $database->get_one("SELECT COUNT(*) FROM images");
 				$database->cache->set("image-count", $total, 600);
 			}
-			return $total;
 		}
 		else if($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
-			return $database->get_one(
+			$total = $database->get_one(
 				$database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
-				array("tag"=>$tags[0])) || 0;
+				array("tag"=>$tags[0]));
 		}
 		else {
 			$querylet = Image::build_search_querylet($tags);
-			return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables) || 0;
+			$total = $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
 		}
+		if(is_null($total)) return 0;
+		return $total;
 	}
 
 	/**