diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-08-28 12:39:43 +0200 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2013-09-19 21:08:32 +0300 |
commit | 466fd8acda010ad330930055925ce26ede1fbf06 (patch) | |
tree | 170c204e0ca535413734df67dbb4a6b6f58f3e98 /apps | |
parent | 392c6b6832edfc37a2956ef3a77fab6020a7a746 (diff) | |
download | nextcloud-server-466fd8acda010ad330930055925ce26ede1fbf06.tar.gz nextcloud-server-466fd8acda010ad330930055925ce26ede1fbf06.zip |
fix getAll(), refactor search by mime & search
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/cache.php | 55 |
1 files changed, 37 insertions, 18 deletions
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; } /** |