delete search-accel stuff - built-in queries are faster now
This commit is contained in:
parent
87d1e21679
commit
3c5e6f0746
3 changed files with 9 additions and 110 deletions
|
@ -146,17 +146,14 @@ class Image
|
|||
|
||||
list($tag_conditions, $img_conditions) = self::terms_to_conditions($tags);
|
||||
|
||||
$result = Image::get_accelerated_result($tag_conditions, $img_conditions, $start, $limit);
|
||||
if (!$result) {
|
||||
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
||||
$querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER))));
|
||||
if ($limit!=null) {
|
||||
$querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));
|
||||
$querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start]));
|
||||
}
|
||||
#var_dump($querylet->sql); var_dump($querylet->variables);
|
||||
$result = $database->get_all_iterable($querylet->sql, $querylet->variables);
|
||||
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
||||
$querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER))));
|
||||
if ($limit!=null) {
|
||||
$querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));
|
||||
$querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start]));
|
||||
}
|
||||
#var_dump($querylet->sql); var_dump($querylet->variables);
|
||||
$result = $database->get_all_iterable($querylet->sql, $querylet->variables);
|
||||
|
||||
Image::$order_sql = null;
|
||||
|
||||
|
@ -191,98 +188,6 @@ class Image
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Accelerator stuff
|
||||
*/
|
||||
public static function get_acceleratable(array $tag_conditions): ?array
|
||||
{
|
||||
$ret = [
|
||||
"yays" => [],
|
||||
"nays" => [],
|
||||
];
|
||||
$yays = 0;
|
||||
$nays = 0;
|
||||
foreach ($tag_conditions as $tq) {
|
||||
if (strpos($tq->tag, "*") !== false) {
|
||||
// can't deal with wildcards
|
||||
return null;
|
||||
}
|
||||
if ($tq->positive) {
|
||||
$yays++;
|
||||
$ret["yays"][] = $tq->tag;
|
||||
} else {
|
||||
$nays++;
|
||||
$ret["nays"][] = $tq->tag;
|
||||
}
|
||||
}
|
||||
if ($yays > 1 || $nays > 0) {
|
||||
return $ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function get_accelerated_result(array $tag_conditions, array $img_conditions, int $offset, ?int $limit): ?PDOStatement
|
||||
{
|
||||
if (!SEARCH_ACCEL || !empty($img_conditions) || isset($_GET['DISABLE_ACCEL'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
global $database;
|
||||
|
||||
$req = Image::get_acceleratable($tag_conditions);
|
||||
if (!$req) {
|
||||
return null;
|
||||
}
|
||||
$req["offset"] = $offset;
|
||||
$req["limit"] = $limit;
|
||||
|
||||
$response = Image::query_accelerator($req);
|
||||
if ($response) {
|
||||
$list = implode(",", $response);
|
||||
$result = $database->execute("SELECT * FROM images WHERE id IN ($list) ORDER BY images.id DESC");
|
||||
} else {
|
||||
$result = $database->execute("SELECT * FROM images WHERE 1=0 ORDER BY images.id DESC");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_accelerated_count(array $tag_conditions, array $img_conditions): ?int
|
||||
{
|
||||
if (!SEARCH_ACCEL || !empty($img_conditions) || isset($_GET['DISABLE_ACCEL'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$req = Image::get_acceleratable($tag_conditions);
|
||||
if (!$req) {
|
||||
return null;
|
||||
}
|
||||
$req["count"] = true;
|
||||
|
||||
return Image::query_accelerator($req);
|
||||
}
|
||||
|
||||
public static function query_accelerator($req)
|
||||
{
|
||||
global $_tracer;
|
||||
$fp = @fsockopen("127.0.0.1", 21212);
|
||||
if (!$fp) {
|
||||
return null;
|
||||
}
|
||||
$req_str = json_encode($req);
|
||||
$_tracer->begin("Accelerator Query", ["req"=>$req_str]);
|
||||
fwrite($fp, $req_str);
|
||||
$data = "";
|
||||
while (($buffer = fgets($fp, 4096)) !== false) {
|
||||
$data .= $buffer;
|
||||
}
|
||||
$_tracer->end();
|
||||
if (!feof($fp)) {
|
||||
die("Error: unexpected fgets() fail in query_accelerator($req_str)\n");
|
||||
}
|
||||
fclose($fp);
|
||||
return json_decode($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Image-related utility functions
|
||||
*/
|
||||
|
@ -313,11 +218,8 @@ class Image
|
|||
$tags[] = "rating:*";
|
||||
}
|
||||
list($tag_conditions, $img_conditions) = self::terms_to_conditions($tags);
|
||||
$total = Image::get_accelerated_count($tag_conditions, $img_conditions);
|
||||
if (is_null($total)) {
|
||||
$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);
|
||||
}
|
||||
$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)) {
|
||||
return 0;
|
||||
|
|
|
@ -26,9 +26,7 @@ _d("COVERAGE", false); // boolean activate xdebug coverage monitor
|
|||
_d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers
|
||||
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
|
||||
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance
|
||||
_d("COMPILE_ELS", false); // boolean pre-build the list of event listeners
|
||||
_d("NICE_URLS", false); // boolean force niceurl mode
|
||||
_d("SEARCH_ACCEL", false); // boolean use search accelerator
|
||||
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
|
||||
_d("VERSION", '2.8-dev'); // string shimmie version
|
||||
_d("TIMEZONE", null); // string timezone
|
||||
|
|
|
@ -11,7 +11,6 @@ define("CACHE_HTTP", false);
|
|||
define("COOKIE_PREFIX", 'shm');
|
||||
define("SPEED_HAX", false);
|
||||
define("NICE_URLS", false);
|
||||
define("SEARCH_ACCEL", false);
|
||||
define("WH_SPLITS", 1);
|
||||
define("VERSION", '2.8-dev');
|
||||
define("BASE_URL", null);
|
||||
|
|
Reference in a new issue