From 312db57f713a5b7afb25730df187bce57e7d08a6 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Tue, 29 Dec 2015 12:06:44 +0100 Subject: [PATCH] Reverted query optimization as I failed to fix the incorrect sorting cased by this http://stackoverflow.com/questions/34399798/similar-mysql-queries-returning-with-different-sorting --- php/modules/Album.php | 14 +++++++++----- php/modules/Settings.php | 12 ------------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/php/modules/Album.php b/php/modules/Album.php index d7adf97..1b8d1c5 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -194,8 +194,8 @@ class Album extends Module { if ($public===false) $return['smartalbums'] = $this->getSmartInfo(); # Albums query - if ($public===false) $query = Database::prepare($this->database, 'SELECT a.id, a.title, a.public, a.sysstamp, a.password, p.thumbs FROM (SELECT album, substring_index(GROUP_CONCAT(thumbUrl ORDER BY star DESC, ' . substr($this->settings['sortingPhotos'], 9) . '), ",", 3) AS thumbs FROM ? GROUP BY album) AS p RIGHT JOIN ? a ON p.album = a.id ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS)); - else $query = Database::prepare($this->database, 'SELECT a.id, a.title, a.public, a.sysstamp, a.password, p.thumbs FROM (SELECT album, substring_index(GROUP_CONCAT(thumbUrl ORDER BY star DESC, ' . substr($this->settings['sortingPhotos'], 9) . '), ",", 3) AS thumbs FROM ? GROUP BY album) AS p RIGHT JOIN ? a ON p.album = a.id WHERE public = 1 AND visible <> 0 ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS)); + if ($public===false) $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS)); + else $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS)); # Execute query $albums = $this->database->query($query); @@ -214,10 +214,14 @@ class Album extends Module { if (($public===true&&$album['password']==='0')|| ($public===false)) { - $k = 0; + # Execute query + $query = Database::prepare($this->database, "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr($this->settings['sortingPhotos'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); + $thumbs = $this->database->query($query); - foreach ($album['thumbs'] as $thumb) { - $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb; + # For each thumb + $k = 0; + while ($thumb = $thumbs->fetch_object()) { + $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; $k++; } diff --git a/php/modules/Settings.php b/php/modules/Settings.php index db3e111..f0f57f4 100755 --- a/php/modules/Settings.php +++ b/php/modules/Settings.php @@ -179,12 +179,6 @@ class Settings extends Module { } - $sorting .= ' '; - - # Append fallback sorting - # Necessary to get a consistent sorting when multiple photos have same values - $sorting .= ', id DESC'; - # Execute query # Do not prepare $sorting because it is a true statement # Preparing (escaping) the sorting would destroy it @@ -241,12 +235,6 @@ class Settings extends Module { } - $sorting .= ' '; - - # Append fallback sorting - # Necessary to get a consistent sorting when multiple albums have same values - $sorting .= ', id DESC'; - # Execute query # Do not prepare $sorting because it is a true statement # Preparing (escaping) the sorting would destroy it