]> source.dussan.org Git - nextcloud-server.git/commitdiff
Improve sorting performance of large lists of files
authorRobin Appelman <icewind@owncloud.com>
Wed, 19 Mar 2014 12:53:59 +0000 (13:53 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 19 Mar 2014 12:53:59 +0000 (13:53 +0100)
apps/files/ajax/rawlist.php
apps/files/lib/helper.php
apps/files_trashbin/lib/helper.php

index 89c21a172fc1408b59e67057c0cfc85f4d528683..6433ddefd69e22b5f6822f31801b4f10f3d1b4a4 100644 (file)
@@ -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));
index b9e41a352bcb615bc8330b92ccaa6b8327b51851..c41e2d155813fd1b3f6333b36566c14c47c55042 100644 (file)
@@ -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());
                }
        }
 
index fe0d1d30a72d5ca2310fe03beba40825337a1e04..9c24332a964dd2227ab1dfd9c5d6d640229a8481 100644 (file)
@@ -2,13 +2,15 @@
 
 namespace OCA\Files_Trashbin;
 
+use OC\Files\FileInfo;
+
 class Helper
 {
        /**
         * Retrieves the contents of a trash bin directory.
         * @param string $dir path to the directory inside the trashbin
         * or empty to retrieve the root of the trashbin
-        * @return array of files
+        * @return \OCP\Files\FileInfo[]
         */
        public static function getTrashFiles($dir){
                $result = array();
@@ -52,6 +54,8 @@ class Helper
 
                $files = array();
                $id = 0;
+               list($storage, $internalPath) = $view->resolvePath($dir);
+               $absoluteDir = $view->getAbsolutePath($dir);
                foreach ($result as $r) {
                        $i = array();
                        $i['id'] = $id++;
@@ -77,7 +81,7 @@ class Helper
                                $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
                        }
                        $i['icon'] = \OCA\Files\Helper::determineIcon($i);
-                       $files[] = $i;
+                       $files[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i);
                }
 
                usort($files, array('\OCA\Files\Helper', 'fileCmp'));