From e8bf576184fdafbe74f3394dc253a56c07be6507 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 26 Jul 2013 14:11:59 +0200 Subject: add initial search in shared files --- apps/files_sharing/lib/cache.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 33cd1428899..28e3cbdb2e1 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -226,7 +226,31 @@ class Shared_Cache extends Cache { * @return array of file data */ public function search($pattern) { - // TODO + + // normalize pattern + $pattern = $this->normalize($pattern); + + $ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); + foreach ($ids as $file) { + $folderBackend = \OCP\Share::getBackend('folder'); + $children = $folderBackend->getChildren($file); + foreach ($children as $child) { + $ids[] = (int)$child['source']; + } + + } + $placeholders = join(',', array_fill(0, count($ids), '?')); + + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag` + FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')'; + $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $ids)); + $files = array(); + while ($row = $result->fetchRow()) { + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; + } + return $files; } /** -- cgit v1.2.3 From 27511d9187a5ffd4d5a087602a9c648e9ec1c06e Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Jul 2013 15:13:00 +0200 Subject: divide ids into chunks of 1k --- apps/files_sharing/lib/cache.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 28e3cbdb2e1..6386f1d2c60 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -239,16 +239,25 @@ class Shared_Cache extends Cache { } } - $placeholders = join(',', array_fill(0, count($ids), '?')); - - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag` - FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')'; - $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $ids)); + $files = array(); - while ($row = $result->fetchRow()) { - $row['mimetype'] = $this->getMimetype($row['mimetype']); - $row['mimepart'] = $this->getMimetype($row['mimepart']); - $files[] = $row; + + // divide into 1k chunks + $chunks = array_chunk($ids, 1000); + + foreach ($chunks as $chunk) { + $placeholders = join(',', array_fill(0, count($chunk), '?')); + + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag` + FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')'; + + $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk)); + + while ($row = $result->fetchRow()) { + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; + } } return $files; } -- cgit v1.2.3 From 392c6b6832edfc37a2956ef3a77fab6020a7a746 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 7 Aug 2013 18:18:40 +0200 Subject: return fixed path, skip shared files outside of 'files' --- apps/files_sharing/lib/cache.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 6386f1d2c60..a4402464481 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -254,9 +254,12 @@ class Shared_Cache extends Cache { $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk)); while ($row = $result->fetchRow()) { - $row['mimetype'] = $this->getMimetype($row['mimetype']); - $row['mimepart'] = $this->getMimetype($row['mimepart']); - $files[] = $row; + if (substr($row['path'], 0, 6)==='files/') { + $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; + } // else skip results out of the files folder } } return $files; -- cgit v1.2.3 From 466fd8acda010ad330930055925ce26ede1fbf06 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 28 Aug 2013 12:39:43 +0200 Subject: fix getAll(), refactor search by mime & search --- apps/files_sharing/lib/cache.php | 55 +++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index a4402464481..82588df42d2 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -230,15 +230,7 @@ class Shared_Cache extends Cache { // normalize pattern $pattern = $this->normalize($pattern); - $ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); - foreach ($ids as $file) { - $folderBackend = \OCP\Share::getBackend('folder'); - $children = $folderBackend->getChildren($file); - foreach ($children as $child) { - $ids[] = (int)$child['source']; - } - - } + $ids = $this->getAll(); $files = array(); @@ -248,7 +240,8 @@ class Shared_Cache extends Cache { foreach ($chunks as $chunk) { $placeholders = join(',', array_fill(0, count($chunk), '?')); - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag` + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, + `encrypted`, `unencrypted_size`, `etag` FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')'; $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk)); @@ -280,13 +273,30 @@ class Shared_Cache extends Cache { } $mimetype = $this->getMimetypeId($mimetype); $ids = $this->getAll(); - $placeholders = join(',', array_fill(0, count($ids), '?')); - $query = \OC_DB::prepare(' - SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` - FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN (' . $placeholders . ')' - ); - $result = $query->execute(array_merge(array($mimetype), $ids)); - return $result->fetchAll(); + + $files = array(); + + // divide into 1k chunks + $chunks = array_chunk($ids, 1000); + + foreach ($chunks as $chunk) { + $placeholders = join(',', array_fill(0, count($ids), '?')); + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, + `encrypted`, `unencrypted_size`, `etag` + FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN (' . $placeholders . ')'; + + $result = \OC_DB::executeAudited($sql, array_merge(array($mimetype), $chunk)); + + while ($row = $result->fetchRow()) { + if (substr($row['path'], 0, 6)==='files/') { + $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; + } // else skip results out of the files folder + } + } + return $files; } /** @@ -308,7 +318,16 @@ class Shared_Cache extends Cache { * @return int[] */ public function getAll() { - return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); + $ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); + $folderBackend = \OCP\Share::getBackend('folder'); + foreach ($ids as $file) { + $children = $folderBackend->getChildren($file); + foreach ($children as $child) { + $ids[] = (int)$child['source']; + } + + } + return $ids; } /** -- cgit v1.2.3 From 3b4020e81131cd526a6bbffe14bc14f1cac4fd60 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 28 Aug 2013 21:04:21 +0200 Subject: add all results, sharing cache also returns entries for shared files in external storages --- apps/files_sharing/lib/cache.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 82588df42d2..acb064f31aa 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -249,10 +249,10 @@ class Shared_Cache extends Cache { while ($row = $result->fetchRow()) { if (substr($row['path'], 0, 6)==='files/') { $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' - $row['mimetype'] = $this->getMimetype($row['mimetype']); - $row['mimepart'] = $this->getMimetype($row['mimepart']); - $files[] = $row; - } // else skip results out of the files folder + } + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; } } return $files; -- cgit v1.2.3 From 6aeb0a99daf28ecb68b010d96369636a99ad77be Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 28 Aug 2013 21:10:06 +0200 Subject: same for search by mime --- apps/files_sharing/lib/cache.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index acb064f31aa..51e8713b97a 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -290,10 +290,10 @@ class Shared_Cache extends Cache { while ($row = $result->fetchRow()) { if (substr($row['path'], 0, 6)==='files/') { $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' - $row['mimetype'] = $this->getMimetype($row['mimetype']); - $row['mimepart'] = $this->getMimetype($row['mimepart']); - $files[] = $row; - } // else skip results out of the files folder + } + $row['mimetype'] = $this->getMimetype($row['mimetype']); + $row['mimepart'] = $this->getMimetype($row['mimepart']); + $files[] = $row; } } return $files; -- cgit v1.2.3 From cd2421c7ee04e6d46481a1d0ae36387757b204fe Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 24 Sep 2013 10:37:58 +0200 Subject: adding PHPDoc comments to getBackend ensure getChildren() is called on an instance of Share_Backend_Collection --- apps/files_sharing/lib/cache.php | 15 ++++++++++----- lib/public/share.php | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 51e8713b97a..123268e240a 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -20,6 +20,7 @@ */ namespace OC\Files\Cache; +use OCP\Share_Backend_Collection; /** * Metadata cache for shared files @@ -320,13 +321,17 @@ class Shared_Cache extends Cache { public function getAll() { $ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); $folderBackend = \OCP\Share::getBackend('folder'); - foreach ($ids as $file) { - $children = $folderBackend->getChildren($file); - foreach ($children as $child) { - $ids[] = (int)$child['source']; + if ($folderBackend instanceof Share_Backend_Collection) { + foreach ($ids as $file) { + /** @var $folderBackend Share_Backend_Collection */ + $children = $folderBackend->getChildren($file); + foreach ($children as $child) { + $ids[] = (int)$child['source']; + } + } - } + return $ids; } diff --git a/lib/public/share.php b/lib/public/share.php index 10922965ea8..41f5ccbf40d 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -745,8 +745,8 @@ class Share { /** * @brief Get the backend class for the specified item type - * @param string Item type - * @return Sharing backend object + * @param string $itemType + * @return Share_Backend */ public static function getBackend($itemType) { if (isset(self::$backends[$itemType])) { -- cgit v1.2.3