diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-03-19 13:53:59 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-03-19 13:53:59 +0100 |
commit | 214357ca68ebd80cc59cd1ee34a5a292feaebbe0 (patch) | |
tree | 0ac3df54dd26431ee963b20f1bcb22fef4bfeb5b /apps/files | |
parent | b9fc240b838439444061824cb191ce22c4c4c052 (diff) | |
download | nextcloud-server-214357ca68ebd80cc59cd1ee34a5a292feaebbe0.tar.gz nextcloud-server-214357ca68ebd80cc59cd1ee34a5a292feaebbe0.zip |
Improve sorting performance of large lists of files
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/ajax/rawlist.php | 5 | ||||
-rw-r--r-- | apps/files/lib/helper.php | 15 |
2 files changed, 11 insertions, 9 deletions
diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 89c21a172fc..6433ddefd69 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -33,6 +33,8 @@ if (is_array($mimetypes) && count($mimetypes)) { } else { $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir)); } +// Sort by name +usort($files, array('\OCA\Files\Helper', 'fileCmp')); $result = array(); foreach ($files as $file) { @@ -51,7 +53,4 @@ foreach ($files as $file) { $result[] = $fileData; } -// Sort by name -usort($result, array('\OCA\Files\Helper', 'fileCmp')); - OC_JSON::success(array('data' => $result)); diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index b9e41a352bc..c41e2d15581 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -51,17 +51,20 @@ class Helper /** * Comparator function to sort files alphabetically and have * the directories appear first - * @param array $a file - * @param array $b file - * @return -1 if $a must come before $b, 1 otherwise + * + * @param \OCP\Files\FileInfo $a file + * @param \OCP\Files\FileInfo $b file + * @return int -1 if $a must come before $b, 1 otherwise */ public static function fileCmp($a, $b) { - if ($a['type'] === 'dir' and $b['type'] !== 'dir') { + $aType = $a->getType(); + $bType = $b->getType(); + if ($aType === 'dir' and $bType !== 'dir') { return -1; - } elseif ($a['type'] !== 'dir' and $b['type'] === 'dir') { + } elseif ($aType !== 'dir' and $bType === 'dir') { return 1; } else { - return strnatcasecmp($a['name'], $b['name']); + return strnatcasecmp($a->getName(), $b->getName()); } } |