diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-10-01 17:13:10 +0400 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-10-10 17:58:00 +0400 |
commit | 5a37703b3ff4ac42294e19917060187666fc917c (patch) | |
tree | 1a721503e0ca81f95eb0929db357a8ce42d334b6 /lib/private/share | |
parent | 088879c4ec64d6964d1a8a9822dc5dc7aa61b176 (diff) |
fix performance issues
Diffstat (limited to 'lib/private/share')
-rw-r--r-- | lib/private/share/share.php | 74 |
1 files changed, 56 insertions, 18 deletions
diff --git a/lib/private/share/share.php b/lib/private/share/share.php index cfdc8aa9ffe..a5010eca149 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -295,8 +295,17 @@ class Share extends \OC\Share\Constants { $shares = array(); $column = ($itemType === 'file' || $itemType === 'folder') ? 'file_source' : 'item_source'; + if ($itemType === 'file' || $itemType === 'folder') { + $column = 'file_source'; + $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE'; + } else { + $column = 'item_source'; + $where = 'WHERE'; + } + + $select = self::createSelectStatement(self::FORMAT_NONE, true); - $where = ' `' . $column . '` = ? AND `item_type` = ? '; + $where .= ' `' . $column . '` = ? AND `item_type` = ? '; $arguments = array($itemSource, $itemType); // for link shares $user === null if ($user !== null) { @@ -304,13 +313,7 @@ class Share extends \OC\Share\Constants { $arguments[] = $user; } - // first check if there is a db entry for the specific user - $query = \OC_DB::prepare( - 'SELECT * - FROM - `*PREFIX*share` - WHERE' . $where - ); + $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` '. $where); $result = \OC_DB::executeAudited($query, $arguments); @@ -323,7 +326,7 @@ class Share extends \OC\Share\Constants { $groups = \OC_Group::getUserGroups($user); $query = \OC_DB::prepare( - 'SELECT `file_target`, `permissions`, `expiration` + 'SELECT * FROM `*PREFIX*share` WHERE @@ -1292,7 +1295,7 @@ class Share extends \OC\Share\Constants { } if (isset($item)) { $collectionTypes = self::getCollectionItemTypes($itemType); - if ($includeCollections && $collectionTypes) { + if ($includeCollections && $collectionTypes && !in_array('folder', $collectionTypes)) { $where .= ' AND ('; } else { $where .= ' AND'; @@ -1316,7 +1319,7 @@ class Share extends \OC\Share\Constants { } } $queryArgs[] = $item; - if ($includeCollections && $collectionTypes) { + if ($includeCollections && $collectionTypes && !in_array('folder', $collectionTypes)) { $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); $where .= ' OR `item_type` IN ('.$placeholders.'))'; $queryArgs = array_merge($queryArgs, $collectionTypes); @@ -1430,7 +1433,7 @@ class Share extends \OC\Share\Constants { $mounts[$row['storage']] = current($mountPoints); } } - if ($mounts[$row['storage']]) { + if (!empty($mounts[$row['storage']])) { $path = $mounts[$row['storage']]->getMountPoint().$row['path']; $relPath = substr($path, $root); // path relative to data/user $row['path'] = rtrim($relPath, '/'); @@ -1478,7 +1481,7 @@ class Share extends \OC\Share\Constants { } } // Check if this is a collection of the requested item type - if ($includeCollections && $collectionTypes && in_array($row['item_type'], $collectionTypes)) { + if ($includeCollections && $collectionTypes && $row['item_type'] !== 'folder' && in_array($row['item_type'], $collectionTypes)) { if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof \OCP\Share_Backend_Collection) { // Collections can be inside collections, check if the item is a collection @@ -1538,6 +1541,15 @@ class Share extends \OC\Share\Constants { $toRemove = $switchedItems[$toRemove]; } unset($items[$toRemove]); + } elseif ($includeCollections && $collectionTypes && in_array($row['item_type'], $collectionTypes)) { + // FIXME: Thats a dirty hack to improve file sharing performance, + // see github issue #10588 for more details + // Need to find a solution which works for all back-ends + $collectionBackend = self::getBackend($row['item_type']); + $sharedParents = $collectionBackend->getParents($row['item_source']); + foreach ($sharedParents as $parent) { + $collectionItems[] = $parent; + } } } if (!empty($collectionItems)) { @@ -1545,6 +1557,20 @@ class Share extends \OC\Share\Constants { } return self::formatResult($items, $column, $backend, $format, $parameters); + } elseif ($includeCollections && $collectionTypes && in_array('folder', $collectionTypes)) { + // FIXME: Thats a dirty hack to improve file sharing performance, + // see github issue #10588 for more details + // Need to find a solution which works for all back-ends + $collectionItems = array(); + $collectionBackend = self::getBackend('folder'); + $sharedParents = $collectionBackend->getParents($item, $shareWith); + foreach ($sharedParents as $parent) { + $collectionItems[] = $parent; + } + if ($limit === 1) { + return reset($collectionItems); + } + return self::formatResult($collectionItems, $column, $backend, $format, $parameters); } return array(); @@ -1798,6 +1824,8 @@ class Share extends \OC\Share\Constants { $backend = self::getBackend($itemType); $l = \OC_L10N::get('lib'); + $column = ($itemType === 'file' || $itemType === 'folder') ? 'file_source' : 'item_source'; + $checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true); if ($checkReshare) { // Check if attempting to share back to owner @@ -1820,12 +1848,22 @@ class Share extends \OC\Share\Constants { } else { // TODO Don't check if inside folder $result['parent'] = $checkReshare['id']; - $result['itemSource'] = $checkReshare['item_source']; - $result['fileSource'] = $checkReshare['file_source']; - $result['suggestedItemTarget'] = $checkReshare['item_target']; - $result['suggestedFileTarget'] = $checkReshare['file_target']; - $result['filePath'] = $checkReshare['file_target']; $result['expirationDate'] = min($expirationDate, $checkReshare['expiration']); + // only suggest the same name as new target if it is a reshare of the + // same file/folder and not the reshare of a child + if ($checkReshare[$column] === $itemSource) { + $result['filePath'] = $checkReshare['file_target']; + $result['itemSource'] = $checkReshare['item_source']; + $result['fileSource'] = $checkReshare['file_source']; + $result['suggestedItemTarget'] = $checkReshare['item_target']; + $result['suggestedFileTarget'] = $checkReshare['file_target']; + } else { + $result['filePath'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $backend->getFilePath($itemSource, $uidOwner) : null; + $result['suggestedItemTarget'] = null; + $result['suggestedFileTarget'] = null; + $result['itemSource'] = $itemSource; + $result['fileSource'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $itemSource : null; + } } } else { $message = 'Sharing %s failed, because resharing is not allowed'; |