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
|
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags=[]): iterable
|
||||||
{
|
{
|
||||||
global $database, $user, $config;
|
global $database, $user, $config;
|
||||||
@ -211,23 +210,35 @@ class Image
|
|||||||
$tag_count = count($tags);
|
$tag_count = count($tags);
|
||||||
|
|
||||||
if ($tag_count === 0) {
|
if ($tag_count === 0) {
|
||||||
|
// total number of images in the DB
|
||||||
$total = $cache->get("image-count");
|
$total = $cache->get("image-count");
|
||||||
if (!$total) {
|
if (!$total) {
|
||||||
$total = (int)$database->get_one("SELECT COUNT(*) FROM images");
|
$total = (int)$database->get_one("SELECT COUNT(*) FROM images");
|
||||||
$cache->set("image-count", $total, 600);
|
$cache->set("image-count", $total, 600);
|
||||||
}
|
}
|
||||||
} elseif ($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
|
} 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(
|
$total = (int)$database->get_one(
|
||||||
"SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)",
|
"SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)",
|
||||||
["tag"=>$tags[0]]
|
["tag"=>$tags[0]]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (Extension::is_enabled(RatingsInfo::KEY)) {
|
// complex query
|
||||||
$tags[] = "rating:*";
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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 (is_null($total)) {
|
if (is_null($total)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -43,26 +43,26 @@ class Index extends Extension
|
|||||||
$count_search_terms = count($search_terms);
|
$count_search_terms = count($search_terms);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#log_debug("index", "Search for ".Tag::implode($search_terms), false, array("terms"=>$search_terms));
|
$fast_page_limit = 500;
|
||||||
|
|
||||||
|
if (SPEED_HAX && $page_number > $fast_page_limit && !$user->can("big_search")) {
|
||||||
|
$this->theme->display_error(
|
||||||
|
404,
|
||||||
|
"Search limit hit",
|
||||||
|
"Only $fast_page_limit pages of results are searchable - " .
|
||||||
|
"if you want to find older results, use more specific search terms"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$total_pages = Image::count_pages($search_terms);
|
$total_pages = Image::count_pages($search_terms);
|
||||||
$images = [];
|
$images = [];
|
||||||
|
|
||||||
|
if (SPEED_HAX && $total_pages > $fast_page_limit && !$user->can("big_search")) {
|
||||||
|
$total_pages = $fast_page_limit;
|
||||||
|
}
|
||||||
|
|
||||||
if (SPEED_HAX) {
|
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) {
|
|
||||||
$this->theme->display_error(
|
|
||||||
404,
|
|
||||||
"Search limit hit",
|
|
||||||
"Only $fast_page_limit pages of results are searchable - " .
|
|
||||||
"if you want to find older results, use more specific search terms"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($count_search_terms === 0 && ($page_number < 10)) {
|
if ($count_search_terms === 0 && ($page_number < 10)) {
|
||||||
// extra caching for the first few post/list pages
|
// extra caching for the first few post/list pages
|
||||||
$images = $cache->get("post-list:$page_number");
|
$images = $cache->get("post-list:$page_number");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user