Browse Source

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
Tobias Reich 8 years ago
parent
commit
312db57f71
2 changed files with 9 additions and 17 deletions
  1. 9 5
      php/modules/Album.php
  2. 0 12
      php/modules/Settings.php

+ 9 - 5
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++;
 					}
 

+ 0 - 12
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