remove redundant scoreql_to_sql
This commit is contained in:
		
							parent
							
								
									1589b42a10
								
							
						
					
					
						commit
						40ab91f8ea
					
				| @ -689,11 +689,11 @@ class Image | |||||||
|             // insert each new tags
 |             // insert each new tags
 | ||||||
|             foreach ($tags as $tag) { |             foreach ($tags as $tag) { | ||||||
|                 $id = $database->get_one( |                 $id = $database->get_one( | ||||||
|                     $database->scoreql_to_sql(" |                     " | ||||||
| 						SELECT id | 						SELECT id | ||||||
| 						FROM tags | 						FROM tags | ||||||
| 						WHERE LOWER(tag) = LOWER(:tag) | 						WHERE LOWER(tag) = LOWER(:tag) | ||||||
| 					"),
 | 					",
 | ||||||
|                     ["tag"=>$tag] |                     ["tag"=>$tag] | ||||||
|                 ); |                 ); | ||||||
|                 if (empty($id)) { |                 if (empty($id)) { | ||||||
| @ -703,10 +703,8 @@ class Image | |||||||
|                         ["tag"=>$tag] |                         ["tag"=>$tag] | ||||||
|                     ); |                     ); | ||||||
|                     $database->execute( |                     $database->execute( | ||||||
|                         $database->scoreql_to_sql( |                         "INSERT INTO image_tags(image_id, tag_id)
 | ||||||
|                             "INSERT INTO image_tags(image_id, tag_id)
 | 							VALUES(:id, (SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag)))",
 | ||||||
| 							VALUES(:id, (SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag)))" |  | ||||||
|                         ), |  | ||||||
|                         ["id"=>$this->id, "tag"=>$tag] |                         ["id"=>$this->id, "tag"=>$tag] | ||||||
|                     ); |                     ); | ||||||
|                 } else { |                 } else { | ||||||
| @ -723,11 +721,11 @@ class Image | |||||||
|                     array_push($written_tags, $id); |                     array_push($written_tags, $id); | ||||||
|                 } |                 } | ||||||
|                 $database->execute( |                 $database->execute( | ||||||
|                     $database->scoreql_to_sql(" |                     " | ||||||
| 						UPDATE tags | 						UPDATE tags | ||||||
| 						SET count = count + 1 | 						SET count = count + 1 | ||||||
| 						WHERE LOWER(tag) = LOWER(:tag) | 						WHERE LOWER(tag) = LOWER(:tag) | ||||||
| 					"),
 | 					",
 | ||||||
|                     ["tag"=>$tag] |                     ["tag"=>$tag] | ||||||
|                 ); |                 ); | ||||||
|             } |             } | ||||||
| @ -933,7 +931,7 @@ class Image | |||||||
|                 $sq .= "ESCAPE '\\'"; |                 $sq .= "ESCAPE '\\'"; | ||||||
|             } |             } | ||||||
|             $tag_ids = $database->get_col( |             $tag_ids = $database->get_col( | ||||||
|                 $database->scoreql_to_sql($sq), |                 $sq, | ||||||
|                 ["tag" => Tag::sqlify($tq->tag)] |                 ["tag" => Tag::sqlify($tq->tag)] | ||||||
|             ); |             ); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -49,11 +49,11 @@ class Tag | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             $newtags = $database->get_one( |             $newtags = $database->get_one( | ||||||
|                 $database->scoreql_to_sql(" |                 " | ||||||
| 					SELECT newtag | 					SELECT newtag | ||||||
| 					FROM aliases | 					FROM aliases | ||||||
| 					WHERE LOWER(oldtag)=LOWER(:tag) | 					WHERE LOWER(oldtag)=LOWER(:tag) | ||||||
| 				"),
 | 				",
 | ||||||
|                 ["tag"=>$tag] |                 ["tag"=>$tag] | ||||||
|             ); |             ); | ||||||
|             if (empty($newtags)) { |             if (empty($newtags)) { | ||||||
|  | |||||||
| @ -160,9 +160,10 @@ class AdminPage extends Extension | |||||||
|     private function set_tag_case() |     private function set_tag_case() | ||||||
|     { |     { | ||||||
|         global $database; |         global $database; | ||||||
|         $database->execute($database->scoreql_to_sql( |         $database->execute( | ||||||
|             "UPDATE tags SET tag=:tag1 WHERE LOWER(tag) = LOWER(:tag2)" |             "UPDATE tags SET tag=:tag1 WHERE LOWER(tag) = LOWER(:tag2)", | ||||||
|         ), ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']]); |             ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']] | ||||||
|  |         ); | ||||||
|         log_info("admin", "Fixed the case of {$_POST['tag']}", "Fixed case"); |         log_info("admin", "Fixed the case of {$_POST['tag']}", "Fixed case"); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -45,14 +45,14 @@ class AutoComplete extends Extension | |||||||
|             $res = $cache->get($cache_key); |             $res = $cache->get($cache_key); | ||||||
|             if (!$res) { |             if (!$res) { | ||||||
|                 $res = $database->get_pairs( |                 $res = $database->get_pairs( | ||||||
|                     $database->scoreql_to_sql(" |                     " | ||||||
| 					SELECT tag, count | 					SELECT tag, count | ||||||
| 					FROM tags | 					FROM tags | ||||||
| 					WHERE LOWER(tag) LIKE LOWER(:search) | 					WHERE LOWER(tag) LIKE LOWER(:search) | ||||||
| 					-- OR LOWER(tag) LIKE LOWER(:cat_search) | 					-- OR LOWER(tag) LIKE LOWER(:cat_search) | ||||||
| 					AND count > 0 | 					AND count > 0 | ||||||
| 					ORDER BY count DESC | 					ORDER BY count DESC | ||||||
| 					$limitSQL"),
 | 					$limitSQL",
 | ||||||
|                     $SQLarr |                     $SQLarr | ||||||
|                 ); |                 ); | ||||||
|                 $cache->set($cache_key, $res, 600); |                 $cache->set($cache_key, $res, 600); | ||||||
|  | |||||||
| @ -85,9 +85,7 @@ class DanbooruApi extends Extension | |||||||
|             $namelist = explode(",", $_GET['name']); |             $namelist = explode(",", $_GET['name']); | ||||||
|             foreach ($namelist as $name) { |             foreach ($namelist as $name) { | ||||||
|                 $sqlresult = $database->get_all( |                 $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] |                     ['tag'=>$name] | ||||||
|                 ); |                 ); | ||||||
|                 foreach ($sqlresult as $row) { |                 foreach ($sqlresult as $row) { | ||||||
|  | |||||||
| @ -268,7 +268,7 @@ class Media extends Extension | |||||||
|         if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, $event->term, $matches)) { |         if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, $event->term, $matches)) { | ||||||
|             $field = $matches[1]; |             $field = $matches[1]; | ||||||
|             if ($field==="unknown") { |             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 { |             } else { | ||||||
|                 $event->add_querylet(new Querylet($database->scoreql_to_sql("$field = SCORE_BOOL_Y"))); |                 $event->add_querylet(new Querylet($database->scoreql_to_sql("$field = SCORE_BOOL_Y"))); | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -118,9 +118,7 @@ class NotATag extends Extension | |||||||
|                     $user->ensure_authed(); |                     $user->ensure_authed(); | ||||||
|                     $input = validate_input(["d_tag"=>"string"]); |                     $input = validate_input(["d_tag"=>"string"]); | ||||||
|                     $database->execute( |                     $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']] |                         ["tag"=>$input['d_tag']] | ||||||
|                     ); |                     ); | ||||||
|                     $page->flash("Image ban removed"); |                     $page->flash("Image ban removed"); | ||||||
| @ -152,13 +150,13 @@ class NotATag extends Extension | |||||||
|             $args["redirect"] = "%".$_GET['redirect']."%"; |             $args["redirect"] = "%".$_GET['redirect']."%"; | ||||||
|         } |         } | ||||||
|         $where = implode(" AND ", $where); |         $where = implode(" AND ", $where); | ||||||
|         return $database->get_all($database->scoreql_to_sql(" |         return $database->get_all(" | ||||||
| 			SELECT * | 			SELECT * | ||||||
| 			FROM untags | 			FROM untags | ||||||
| 			WHERE $where | 			WHERE $where | ||||||
| 			ORDER BY tag | 			ORDER BY tag | ||||||
| 			LIMIT :limit | 			LIMIT :limit | ||||||
| 			OFFSET :offset | 			OFFSET :offset | ||||||
| 			"), $args);
 | 		", $args);
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -574,15 +574,13 @@ class OuroborosAPI extends Extension | |||||||
|         switch ($order) { |         switch ($order) { | ||||||
|             case 'name': |             case 'name': | ||||||
|                 $tag_data = $database->get_col( |                 $tag_data = $database->get_col( | ||||||
|                     $database->scoreql_to_sql( |                     " | ||||||
|                         " |                         SELECT DISTINCT | ||||||
|                                                         SELECT DISTINCT |                             id, LOWER(substr(tag, 1, 1)), count | ||||||
|                                                             id, LOWER(substr(tag, 1, 1)), count |                         FROM tags | ||||||
|                                                         FROM tags |                         WHERE count >= :tags_min | ||||||
|                                                         WHERE count >= :tags_min |                         ORDER BY LOWER(substr(tag, 1, 1)) LIMIT :start, :max_items | ||||||
|                                                         ORDER BY LOWER(substr(tag, 1, 1)) LIMIT :start, :max_items |                     ",
 | ||||||
|                                                     " |  | ||||||
|                     ), |  | ||||||
|                     ['tags_min' => $config->get_int(TagListConfig::TAGS_MIN), 'start' => $start, 'max_items' => $limit] |                     ['tags_min' => $config->get_int(TagListConfig::TAGS_MIN), 'start' => $start, 'max_items' => $limit] | ||||||
|                 ); |                 ); | ||||||
|                 break; |                 break; | ||||||
|  | |||||||
| @ -78,18 +78,18 @@ class TagCategories extends Extension | |||||||
|             $count = $matches[3]; |             $count = $matches[3]; | ||||||
| 
 | 
 | ||||||
|             $types = $database->get_col( |             $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)) { |             if (in_array($type, $types)) { | ||||||
|                 $event->add_querylet( |                 $event->add_querylet( | ||||||
|                     new Querylet($database->scoreql_to_sql("EXISTS (
 |                     new Querylet("EXISTS (
 | ||||||
| 					    SELECT 1 | 					    SELECT 1 | ||||||
| 					    FROM image_tags it | 					    FROM image_tags it | ||||||
| 					    LEFT JOIN tags t ON it.tag_id = t.id | 					    LEFT JOIN tags t ON it.tag_id = t.id | ||||||
| 					    WHERE images.id = it.image_id | 					    WHERE images.id = it.image_id | ||||||
| 					    GROUP BY image_id | 					    GROUP BY image_id | ||||||
| 					    HAVING SUM(CASE WHEN LOWER(t.tag) LIKE LOWER('$type:%') THEN 1 ELSE 0 END) $cmp $count | 					    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; |             $res = null; | ||||||
|             $cache->get($cache_key); |             $cache->get($cache_key); | ||||||
|             if (!$res) { |             if (!$res) { | ||||||
|                 $res = $database->get_col($database->scoreql_to_sql(" |                 $res = $database->get_col(" | ||||||
| 					SELECT tag | 					SELECT tag | ||||||
| 					FROM tags | 					FROM tags | ||||||
| 					WHERE LOWER(tag) LIKE LOWER(:search) | 					WHERE LOWER(tag) LIKE LOWER(:search) | ||||||
| 						AND count > 0 | 						AND count > 0 | ||||||
| 					$limitSQL | 					$limitSQL | ||||||
| 				"), $SQLarr);
 | 				", $SQLarr);
 | ||||||
|                 $cache->set($cache_key, $res, 600); |                 $cache->set($cache_key, $res, 600); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -233,13 +233,13 @@ class TagList extends Extension | |||||||
| 
 | 
 | ||||||
|         $tags_min = $this->get_tags_min(); |         $tags_min = $this->get_tags_min(); | ||||||
| 
 | 
 | ||||||
|         $tag_data = $database->get_col($database->scoreql_to_sql(" |         $tag_data = $database->get_col(" | ||||||
| 			SELECT DISTINCT | 			SELECT DISTINCT | ||||||
| 				LOWER(substr(tag, 1, 1)) | 				LOWER(substr(tag, 1, 1)) | ||||||
| 			FROM tags | 			FROM tags | ||||||
| 			WHERE count >= :tags_min | 			WHERE count >= :tags_min | ||||||
| 			ORDER BY LOWER(substr(tag, 1, 1)) | 			ORDER BY LOWER(substr(tag, 1, 1)) | ||||||
| 		"), ["tags_min"=>$tags_min]);
 | 		", ["tags_min"=>$tags_min]);
 | ||||||
| 
 | 
 | ||||||
|         $html = "<span class='atoz'>"; |         $html = "<span class='atoz'>"; | ||||||
|         foreach ($tag_data as $a) { |         foreach ($tag_data as $a) { | ||||||
| @ -274,7 +274,7 @@ class TagList extends Extension | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // SHIT: PDO/pgsql has problems using the same named param twice -_-;;
 |         // 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 | 				SELECT | ||||||
| 					tag, | 					tag, | ||||||
| 					FLOOR(LOG(2.7, LOG(2.7, count - :tags_min2 + 1)+1)*1.5*100)/100 AS scaled | 					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 | 				WHERE count >= :tags_min | ||||||
| 				AND LOWER(tag) LIKE LOWER(:starts_with) | 				AND LOWER(tag) LIKE LOWER(:starts_with) | ||||||
| 				ORDER BY LOWER(tag) | 				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 = ""; |         $html = ""; | ||||||
|         if ($config->get_bool(TagListConfig::PAGES)) { |         if ($config->get_bool(TagListConfig::PAGES)) { | ||||||
|  | |||||||
| @ -266,21 +266,22 @@ class Wiki extends Extension | |||||||
|         global $database; |         global $database; | ||||||
|         // first try and get the actual page
 |         // first try and get the actual page
 | ||||||
|         $row = $database->get_row( |         $row = $database->get_row( | ||||||
|             $database->scoreql_to_sql(" |             " | ||||||
| 				SELECT * | 				SELECT * | ||||||
| 				FROM wiki_pages | 				FROM wiki_pages | ||||||
| 				WHERE LOWER(title) LIKE LOWER(:title) | 				WHERE LOWER(title) LIKE LOWER(:title) | ||||||
| 				ORDER BY revision DESC"),
 | 				ORDER BY revision DESC | ||||||
|             ["title"=>$title] | 			", ["title"=>$title]
 | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         // fall back to wiki:default
 |         // fall back to wiki:default
 | ||||||
|         if (empty($row)) { |         if (empty($row)) { | ||||||
|             $row = $database->get_row(" |             $row = $database->get_row(" | ||||||
| 					SELECT * |                 SELECT * | ||||||
| 					FROM wiki_pages |                 FROM wiki_pages | ||||||
| 					WHERE title LIKE :title |                 WHERE title LIKE :title | ||||||
| 					ORDER BY revision DESC", ["title"=>"wiki:default"]);
 |                 ORDER BY revision DESC | ||||||
|  | 			", ["title"=>"wiki:default"]);
 | ||||||
| 
 | 
 | ||||||
|             // fall further back to manual
 |             // fall further back to manual
 | ||||||
|             if (empty($row)) { |             if (empty($row)) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user