remove redundant scoreql_to_sql
This commit is contained in:
parent
1589b42a10
commit
40ab91f8ea
11 changed files with 45 additions and 51 deletions
|
@ -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)]
|
||||
);
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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")));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
)"))
|
||||
)")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = "<span class='atoz'>";
|
||||
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)) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Reference in a new issue