From 759ce874e724147d49b3ad5afd13183f721e5d0e Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Mon, 10 Feb 2014 18:04:34 +0100 Subject: [PATCH] MySQL select performance (#79) --- php/modules/album.php | 12 ++++++------ php/modules/misc.php | 4 ++-- php/modules/photo.php | 7 +++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/php/modules/album.php b/php/modules/album.php index a522172..66c6639 100755 --- a/php/modules/album.php +++ b/php/modules/album.php @@ -31,8 +31,8 @@ function getAlbums($public) { if (!$public) $return = getSmartInfo(); // Albums - if ($public) $query = "SELECT * FROM lychee_albums WHERE public = 1"; - else $query = "SELECT * FROM lychee_albums"; + if ($public) $query = "SELECT id, title, public, sysdate, password FROM lychee_albums WHERE public = 1"; + else $query = "SELECT id, title, public, sysdate, password FROM lychee_albums"; $result = $database->query($query) OR exit("Error: $result
".$database->error); $i = 0; @@ -243,15 +243,15 @@ function getAlbumArchive($albumID) { switch($albumID) { case 's': - $query = "SELECT * FROM lychee_photos WHERE public = '1';"; + $query = "SELECT url FROM lychee_photos WHERE public = '1';"; $zipTitle = "Public"; break; case 'f': - $query = "SELECT * FROM lychee_photos WHERE star = '1';"; + $query = "SELECT url FROM lychee_photos WHERE star = '1';"; $zipTitle = "Starred"; break; default: - $query = "SELECT * FROM lychee_photos WHERE album = '$albumID';"; + $query = "SELECT url FROM lychee_photos WHERE album = '$albumID';"; $zipTitle = "Unsorted"; } @@ -265,7 +265,7 @@ function getAlbumArchive($albumID) { $i++; } - $result = $database->query("SELECT * FROM lychee_albums WHERE id = '$albumID';"); + $result = $database->query("SELECT title FROM lychee_albums WHERE id = '$albumID' LIMIT 1;"); $row = $result->fetch_object(); if ($albumID!=0&&is_numeric($albumID)) $zipTitle = $row->title; $filename = "../data/$zipTitle.zip"; diff --git a/php/modules/misc.php b/php/modules/misc.php index 7991bd8..41768d7 100755 --- a/php/modules/misc.php +++ b/php/modules/misc.php @@ -16,7 +16,7 @@ function openGraphHeader($photoID) { $photoID = mysqli_real_escape_string($database, $photoID); if (!is_numeric($photoID)) return false; - $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';"); + $result = $database->query("SELECT title, description, url FROM lychee_photos WHERE id = '$photoID';"); $row = $result->fetch_object(); $parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); @@ -54,7 +54,7 @@ function search($term) { } // Albums - $result = $database->query("SELECT * FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';"); + $result = $database->query("SELECT id, title, public, sysdate, password FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';"); $i = 0; while($row = $result->fetch_object()) { diff --git a/php/modules/photo.php b/php/modules/photo.php index 47b5f36..dd2af21 100755 --- a/php/modules/photo.php +++ b/php/modules/photo.php @@ -132,7 +132,7 @@ function deletePhoto($photoIDs) { global $database; - $result = $database->query("SELECT * FROM lychee_photos WHERE id IN ($photoIDs);"); + $result = $database->query("SELECT id, url, thumbUrl FROM lychee_photos WHERE id IN ($photoIDs);"); while ($row = $result->fetch_object()) { @@ -160,12 +160,11 @@ function isPhotoPublic($photoID, $password) { global $database; - $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';"; + $query = "SELECT public, album FROM lychee_photos WHERE id = '$photoID';"; $result = $database->query($query); $row = $result->fetch_object(); - if (!is_numeric($photoID)&&!$row) return true; if ($row->public==1) return true; else { $cAP = checkAlbumPassword($row->album, $password); @@ -180,7 +179,7 @@ function getPhotoArchive($photoID) { global $database; - $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';"); + $result = $database->query("SELECT title, url FROM lychee_photos WHERE id = '$photoID';"); $row = $result->fetch_object(); $extension = array_reverse(explode('.', $row->url));