From f87701b1c002673304a68762b97190a67af98dd3 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Mon, 21 Dec 2015 15:09:05 +0100 Subject: [PATCH] Improved loading performance by combining multiple queries #372 #241 --- php/modules/Album.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/php/modules/Album.php b/php/modules/Album.php index 1b8d1c5..d7adf97 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 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)); + 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)); # Execute query $albums = $this->database->query($query); @@ -214,14 +214,10 @@ class Album extends Module { if (($public===true&&$album['password']==='0')|| ($public===false)) { - # 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); - - # For each thumb $k = 0; - while ($thumb = $thumbs->fetch_object()) { - $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; + + foreach ($album['thumbs'] as $thumb) { + $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb; $k++; }