if we're past the searchable number of pages, don't bother counting the number of pages, just 404
This commit is contained in:
parent
7d4008bae8
commit
9216be3c96
@ -134,7 +134,6 @@ class Image
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags=[]): iterable
|
||||
{
|
||||
global $database, $user, $config;
|
||||
@ -211,23 +210,35 @@ class Image
|
||||
$tag_count = count($tags);
|
||||
|
||||
if ($tag_count === 0) {
|
||||
// total number of images in the DB
|
||||
$total = $cache->get("image-count");
|
||||
if (!$total) {
|
||||
$total = (int)$database->get_one("SELECT COUNT(*) FROM images");
|
||||
$cache->set("image-count", $total, 600);
|
||||
}
|
||||
} elseif ($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
|
||||
// one tag - we can look that up directly
|
||||
// TODO: one negative tag = (total - tag.count)
|
||||
$total = (int)$database->get_one(
|
||||
"SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)",
|
||||
["tag"=>$tags[0]]
|
||||
);
|
||||
} else {
|
||||
// complex query
|
||||
$total = $cache->get("image-count:" . Tag::implode($tags));
|
||||
if(!$total) {
|
||||
if (Extension::is_enabled(RatingsInfo::KEY)) {
|
||||
$tags[] = "rating:*";
|
||||
}
|
||||
list($tag_conditions, $img_conditions) = self::terms_to_conditions($tags);
|
||||
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
||||
$total = (int)$database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
|
||||
if (SPEED_HAX && $total > 5000) {
|
||||
// when we have a ton of images, the count
|
||||
// won't change dramatically very often
|
||||
$cache->set("image-count:" . Tag::implode($tags), $total, 3600);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($total)) {
|
||||
return 0;
|
||||
|
@ -43,17 +43,9 @@ class Index extends Extension
|
||||
$count_search_terms = count($search_terms);
|
||||
|
||||
try {
|
||||
#log_debug("index", "Search for ".Tag::implode($search_terms), false, array("terms"=>$search_terms));
|
||||
$total_pages = Image::count_pages($search_terms);
|
||||
$images = [];
|
||||
|
||||
if (SPEED_HAX) {
|
||||
if (!$user->can("big_search")) {
|
||||
$fast_page_limit = 500;
|
||||
if ($total_pages > $fast_page_limit) {
|
||||
$total_pages = $fast_page_limit;
|
||||
}
|
||||
if ($page_number > $fast_page_limit) {
|
||||
|
||||
if (SPEED_HAX && $page_number > $fast_page_limit && !$user->can("big_search")) {
|
||||
$this->theme->display_error(
|
||||
404,
|
||||
"Search limit hit",
|
||||
@ -62,7 +54,15 @@ class Index extends Extension
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$total_pages = Image::count_pages($search_terms);
|
||||
$images = [];
|
||||
|
||||
if (SPEED_HAX && $total_pages > $fast_page_limit && !$user->can("big_search")) {
|
||||
$total_pages = $fast_page_limit;
|
||||
}
|
||||
|
||||
if (SPEED_HAX) {
|
||||
if ($count_search_terms === 0 && ($page_number < 10)) {
|
||||
// extra caching for the first few post/list pages
|
||||
$images = $cache->get("post-list:$page_number");
|
||||
|
Loading…
x
Reference in New Issue
Block a user