From 40ab91f8ea5746d77aedc0d35377e7e37f342f29 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 1 Feb 2020 22:44:50 +0000 Subject: [PATCH] remove redundant scoreql_to_sql --- core/imageboard/image.php | 16 +++++++--------- core/imageboard/tag.php | 4 ++-- ext/admin/main.php | 7 ++++--- ext/autocomplete/main.php | 6 +++--- ext/danbooru_api/main.php | 4 +--- ext/media/main.php | 2 +- ext/not_a_tag/main.php | 8 +++----- ext/ouroboros_api/main.php | 16 +++++++--------- ext/tag_categories/main.php | 6 +++--- ext/tag_list/main.php | 12 ++++++------ ext/wiki/main.php | 15 ++++++++------- 11 files changed, 45 insertions(+), 51 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index ca98d13f..798f4aab 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -689,11 +689,11 @@ class Image // insert each new tags foreach ($tags as $tag) { $id = $database->get_one( - $database->scoreql_to_sql(" + " SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag) - "), + ", ["tag"=>$tag] ); if (empty($id)) { @@ -703,10 +703,8 @@ class Image ["tag"=>$tag] ); $database->execute( - $database->scoreql_to_sql( - "INSERT INTO image_tags(image_id, tag_id) - VALUES(:id, (SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag)))" - ), + "INSERT INTO image_tags(image_id, tag_id) + VALUES(:id, (SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag)))", ["id"=>$this->id, "tag"=>$tag] ); } else { @@ -723,11 +721,11 @@ class Image array_push($written_tags, $id); } $database->execute( - $database->scoreql_to_sql(" + " UPDATE tags SET count = count + 1 WHERE LOWER(tag) = LOWER(:tag) - "), + ", ["tag"=>$tag] ); } @@ -933,7 +931,7 @@ class Image $sq .= "ESCAPE '\\'"; } $tag_ids = $database->get_col( - $database->scoreql_to_sql($sq), + $sq, ["tag" => Tag::sqlify($tq->tag)] ); diff --git a/core/imageboard/tag.php b/core/imageboard/tag.php index a0bc1ca1..05008170 100644 --- a/core/imageboard/tag.php +++ b/core/imageboard/tag.php @@ -49,11 +49,11 @@ class Tag } $newtags = $database->get_one( - $database->scoreql_to_sql(" + " SELECT newtag FROM aliases WHERE LOWER(oldtag)=LOWER(:tag) - "), + ", ["tag"=>$tag] ); if (empty($newtags)) { diff --git a/ext/admin/main.php b/ext/admin/main.php index 0f7a99ff..36bb3198 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -160,9 +160,10 @@ class AdminPage extends Extension private function set_tag_case() { global $database; - $database->execute($database->scoreql_to_sql( - "UPDATE tags SET tag=:tag1 WHERE LOWER(tag) = LOWER(:tag2)" - ), ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']]); + $database->execute( + "UPDATE tags SET tag=:tag1 WHERE LOWER(tag) = LOWER(:tag2)", + ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']] + ); log_info("admin", "Fixed the case of {$_POST['tag']}", "Fixed case"); return true; } diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index 4749b3db..418ba726 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -45,14 +45,14 @@ class AutoComplete extends Extension $res = $cache->get($cache_key); if (!$res) { $res = $database->get_pairs( - $database->scoreql_to_sql(" + " SELECT tag, count FROM tags - WHERE LOWER(tag) LIKE LOWER(:search) + WHERE LOWER(tag) LIKE LOWER(:search) -- OR LOWER(tag) LIKE LOWER(:cat_search) AND count > 0 ORDER BY count DESC - $limitSQL"), + $limitSQL", $SQLarr ); $cache->set($cache_key, $res, 600); diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php index 298e5863..ec3bf9f8 100644 --- a/ext/danbooru_api/main.php +++ b/ext/danbooru_api/main.php @@ -85,9 +85,7 @@ class DanbooruApi extends Extension $namelist = explode(",", $_GET['name']); foreach ($namelist as $name) { $sqlresult = $database->get_all( - $database->scoreql_to_sql( - "SELECT id,tag,count FROM tags WHERE LOWER(tag) = LOWER(:tag)" - ), + "SELECT id,tag,count FROM tags WHERE LOWER(tag) = LOWER(:tag)", ['tag'=>$name] ); foreach ($sqlresult as $row) { diff --git a/ext/media/main.php b/ext/media/main.php index 67d1aeee..cc2202a8 100644 --- a/ext/media/main.php +++ b/ext/media/main.php @@ -268,7 +268,7 @@ class Media extends Extension if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, $event->term, $matches)) { $field = $matches[1]; if ($field==="unknown") { - $event->add_querylet(new Querylet($database->scoreql_to_sql("video IS NULL OR audio IS NULL OR image IS NULL"))); + $event->add_querylet(new Querylet("video IS NULL OR audio IS NULL OR image IS NULL")); } else { $event->add_querylet(new Querylet($database->scoreql_to_sql("$field = SCORE_BOOL_Y"))); } diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php index b82d9a4e..52b9fee6 100644 --- a/ext/not_a_tag/main.php +++ b/ext/not_a_tag/main.php @@ -118,9 +118,7 @@ class NotATag extends Extension $user->ensure_authed(); $input = validate_input(["d_tag"=>"string"]); $database->execute( - $database->scoreql_to_sql( - "DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)" - ), + "DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)", ["tag"=>$input['d_tag']] ); $page->flash("Image ban removed"); @@ -152,13 +150,13 @@ class NotATag extends Extension $args["redirect"] = "%".$_GET['redirect']."%"; } $where = implode(" AND ", $where); - return $database->get_all($database->scoreql_to_sql(" + return $database->get_all(" SELECT * FROM untags WHERE $where ORDER BY tag LIMIT :limit OFFSET :offset - "), $args); + ", $args); } } diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index 592c397a..dfbcdcba 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -574,15 +574,13 @@ class OuroborosAPI extends Extension switch ($order) { case 'name': $tag_data = $database->get_col( - $database->scoreql_to_sql( - " - SELECT DISTINCT - id, LOWER(substr(tag, 1, 1)), count - FROM tags - WHERE count >= :tags_min - ORDER BY LOWER(substr(tag, 1, 1)) LIMIT :start, :max_items - " - ), + " + SELECT DISTINCT + id, LOWER(substr(tag, 1, 1)), count + FROM tags + WHERE count >= :tags_min + ORDER BY LOWER(substr(tag, 1, 1)) LIMIT :start, :max_items + ", ['tags_min' => $config->get_int(TagListConfig::TAGS_MIN), 'start' => $start, 'max_items' => $limit] ); break; diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index f9579ffe..d22a0b5e 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -78,18 +78,18 @@ class TagCategories extends Extension $count = $matches[3]; $types = $database->get_col( - $database->scoreql_to_sql('SELECT LOWER(category) FROM image_tag_categories') + 'SELECT LOWER(category) FROM image_tag_categories' ); if (in_array($type, $types)) { $event->add_querylet( - new Querylet($database->scoreql_to_sql("EXISTS ( + new Querylet("EXISTS ( SELECT 1 FROM image_tags it LEFT JOIN tags t ON it.tag_id = t.id WHERE images.id = it.image_id GROUP BY image_id HAVING SUM(CASE WHEN LOWER(t.tag) LIKE LOWER('$type:%') THEN 1 ELSE 0 END) $cmp $count - )")) + )") ); } } diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 71eea902..d692c5f7 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -66,13 +66,13 @@ class TagList extends Extension $res = null; $cache->get($cache_key); if (!$res) { - $res = $database->get_col($database->scoreql_to_sql(" + $res = $database->get_col(" SELECT tag FROM tags WHERE LOWER(tag) LIKE LOWER(:search) AND count > 0 $limitSQL - "), $SQLarr); + ", $SQLarr); $cache->set($cache_key, $res, 600); } @@ -233,13 +233,13 @@ class TagList extends Extension $tags_min = $this->get_tags_min(); - $tag_data = $database->get_col($database->scoreql_to_sql(" + $tag_data = $database->get_col(" SELECT DISTINCT LOWER(substr(tag, 1, 1)) FROM tags WHERE count >= :tags_min ORDER BY LOWER(substr(tag, 1, 1)) - "), ["tags_min"=>$tags_min]); + ", ["tags_min"=>$tags_min]); $html = ""; foreach ($tag_data as $a) { @@ -274,7 +274,7 @@ class TagList extends Extension } // SHIT: PDO/pgsql has problems using the same named param twice -_-;; - $tag_data = $database->get_all($database->scoreql_to_sql(" + $tag_data = $database->get_all(" SELECT tag, FLOOR(LOG(2.7, LOG(2.7, count - :tags_min2 + 1)+1)*1.5*100)/100 AS scaled @@ -282,7 +282,7 @@ class TagList extends Extension WHERE count >= :tags_min AND LOWER(tag) LIKE LOWER(:starts_with) ORDER BY LOWER(tag) - "), ["tags_min"=>$tags_min, "tags_min2"=>$tags_min, "starts_with"=>$starts_with]); + ", ["tags_min"=>$tags_min, "tags_min2"=>$tags_min, "starts_with"=>$starts_with]); $html = ""; if ($config->get_bool(TagListConfig::PAGES)) { diff --git a/ext/wiki/main.php b/ext/wiki/main.php index c58038d9..58d6ac2b 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -266,21 +266,22 @@ class Wiki extends Extension global $database; // first try and get the actual page $row = $database->get_row( - $database->scoreql_to_sql(" + " SELECT * FROM wiki_pages WHERE LOWER(title) LIKE LOWER(:title) - ORDER BY revision DESC"), - ["title"=>$title] + ORDER BY revision DESC + ", ["title"=>$title] ); // fall back to wiki:default if (empty($row)) { $row = $database->get_row(" - SELECT * - FROM wiki_pages - WHERE title LIKE :title - ORDER BY revision DESC", ["title"=>"wiki:default"]); + SELECT * + FROM wiki_pages + WHERE title LIKE :title + ORDER BY revision DESC + ", ["title"=>"wiki:default"]); // fall further back to manual if (empty($row)) {