From d418e176ce4ce3ee07a5b9e632150470c0387f87 Mon Sep 17 00:00:00 2001
From: Joas Schilling <nickvergessen@gmx.de>
Date: Wed, 9 Apr 2014 15:01:39 +0200
Subject: [PATCH] Do not query when the list is empty

---
 lib/private/share/share.php | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 3d22f6fd45..59826d0303 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -210,21 +210,23 @@ class Share extends \OC\Share\Constants {
 			$fileTargetIDs = array_keys($fileTargets);
 			$fileTargetIDs = array_unique($fileTargetIDs);
 
-			$query = \OC_DB::prepare(
-				'SELECT `fileid`, `path`
-				FROM `*PREFIX*filecache`
-				WHERE `fileid` IN (' . implode(',', $fileTargetIDs) . ')'
-			);
-			$result = $query->execute();
+			if (!empty($fileTargetIDs)) {
+				$query = \OC_DB::prepare(
+					'SELECT `fileid`, `path`
+					FROM `*PREFIX*filecache`
+					WHERE `fileid` IN (' . implode(',', $fileTargetIDs) . ')'
+				);
+				$result = $query->execute();
 
-			if (\OCP\DB::isError($result)) {
-				\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
-			} else {
-				while ($row = $result->fetchRow()) {
-					foreach ($fileTargets[$row['fileid']] as $uid => $shareData) {
-						$sharedPath = '/Shared' . $shareData['file_target'];
-						$sharedPath .= substr($path, strlen($row['path']) -5);
-						$sharePaths[$uid] = $sharedPath;
+				if (\OCP\DB::isError($result)) {
+					\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+				} else {
+					while ($row = $result->fetchRow()) {
+						foreach ($fileTargets[$row['fileid']] as $uid => $shareData) {
+							$sharedPath = '/Shared' . $shareData['file_target'];
+							$sharedPath .= substr($path, strlen($row['path']) -5);
+							$sharePaths[$uid] = $sharedPath;
+						}
 					}
 				}
 			}
-- 
GitLab