summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-22 15:00:57 +0500
committerilotterytea <iltsu@alright.party>2025-04-22 15:00:57 +0500
commit73fdfe1795b2c1be4914f13bf973c83beac5050b (patch)
tree4047e4500bb92df45519aeacf82ae876f1787ea4 /public
parentecba4a77a76aa8dafec78b0336bf0d382be66394 (diff)
upd: unnecessary check in search requests
Diffstat (limited to 'public')
-rw-r--r--public/emotes/index.php22
-rw-r--r--public/users.php16
2 files changed, 11 insertions, 27 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php
index 4cddc47..b074e0a 100644
--- a/public/emotes/index.php
+++ b/public/emotes/index.php
@@ -12,7 +12,7 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS);
function display_list_emotes(PDO &$db, int $page, int $limit): array
{
- $search = $_GET["q"] ?? "";
+ $search = "%" . ($_GET["q"] ?? "") . "%";
$user_id = $_SESSION["user_id"] ?? "-1";
$offset = $page * $limit;
$stmt = $db->prepare("SELECT e.*,
@@ -22,25 +22,15 @@ function display_list_emotes(PDO &$db, int $page, int $limit): array
INNER JOIN emote_sets es ON es.id = ec.emote_set_id
WHERE ec.emote_id = e.id AND es.owner_id = ?
) THEN 1 ELSE 0 END AS is_in_user_set
- FROM emotes e " .
- (($search != "") ? "WHERE e.code LIKE ?" : "")
- .
- "
+ FROM emotes e WHERE e.code LIKE ?
ORDER BY e.created_at ASC
LIMIT ? OFFSET ?
");
- if ($search == "") {
- $stmt->bindParam(1, $user_id, PDO::PARAM_INT);
- $stmt->bindParam(2, $limit, PDO::PARAM_INT);
- $stmt->bindParam(3, $offset, PDO::PARAM_INT);
- } else {
- $search = "%$search%";
- $stmt->bindParam(1, $user_id, PDO::PARAM_INT);
- $stmt->bindParam(2, $search, PDO::PARAM_STR);
- $stmt->bindParam(3, $limit, PDO::PARAM_INT);
- $stmt->bindParam(4, $offset, PDO::PARAM_INT);
- }
+ $stmt->bindParam(1, $user_id, PDO::PARAM_INT);
+ $stmt->bindParam(2, $search, PDO::PARAM_STR);
+ $stmt->bindParam(3, $limit, PDO::PARAM_INT);
+ $stmt->bindParam(4, $offset, PDO::PARAM_INT);
$stmt->execute();
diff --git a/public/users.php b/public/users.php
index 06aa459..54c7aed 100644
--- a/public/users.php
+++ b/public/users.php
@@ -17,20 +17,14 @@ if ($id == "") {
$page = $_GET["p"] ?? "0";
$limit = 50;
$offset = $page * $limit;
- $search = $_GET["q"] ?? "";
+ $search = "%" . ($_GET["q"] ?? "") . "%";
$stmt = $db->prepare("SELECT id, username, joined_at, last_active_at
FROM users
- " . ($search != "" ? " WHERE username LIKE ? " : "") . "
+ WHERE username LIKE ?
ORDER BY last_active_at DESC LIMIT ? OFFSET ?");
- if ($search == "") {
- $stmt->bindParam(1, $limit, PDO::PARAM_INT);
- $stmt->bindParam(2, $offset, PDO::PARAM_INT);
- } else {
- $search = "%$search%";
- $stmt->bindParam(1, $search, PDO::PARAM_STR);
- $stmt->bindParam(2, $limit, PDO::PARAM_INT);
- $stmt->bindParam(3, $offset, PDO::PARAM_INT);
- }
+ $stmt->bindParam(1, $search, PDO::PARAM_STR);
+ $stmt->bindParam(2, $limit, PDO::PARAM_INT);
+ $stmt->bindParam(3, $offset, PDO::PARAM_INT);
$stmt->execute();
$all_user_count = $search ? $stmt->rowCount() : $db->query("SELECT COUNT(*) FROM users")->fetch()[0];