Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / filerepo / backend / SwiftFileBackend.php
index 12fc801..36d4334 100644 (file)
@@ -742,6 +742,10 @@ class SwiftFileBackend extends FileBackendStore {
         */
        public function getDirListPageInternal( $fullCont, $dir, &$after, $limit, array $params ) {
                $dirs = array();
+               if ( $after === INF ) {
+                       return $dirs; // nothing more
+               }
+               wfProfileIn( __METHOD__ . '-' . $this->name );
 
                try {
                        $container = $this->getContainer( $fullCont );
@@ -753,7 +757,6 @@ class SwiftFileBackend extends FileBackendStore {
                                        if ( substr( $object, -1 ) === '/' ) {
                                                $dirs[] = $object; // directories end in '/'
                                        }
-                                       $after = $object; // update last item
                                }
                        // Recursive: list all dirs under $dir and its subdirs
                        } else {
@@ -779,15 +782,20 @@ class SwiftFileBackend extends FileBackendStore {
                                                }
                                                $lastDir = $objectDir;
                                        }
-                                       $after = $object; // update last item
                                }
                        }
+                       if ( count( $objects ) < $limit ) {
+                               $after = INF; // avoid a second RTT
+                       } else {
+                               $after = end( $objects ); // update last item
+                       }
                } catch ( NoSuchContainerException $e ) {
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, null, __METHOD__,
                                array( 'cont' => $fullCont, 'dir' => $dir ) );
                }
 
+               wfProfileOut( __METHOD__ . '-' . $this->name );
                return $dirs;
        }
 
@@ -807,6 +815,10 @@ class SwiftFileBackend extends FileBackendStore {
         */
        public function getFileListPageInternal( $fullCont, $dir, &$after, $limit, array $params ) {
                $files = array();
+               if ( $after === INF ) {
+                       return $files; // nothing more
+               }
+               wfProfileIn( __METHOD__ . '-' . $this->name );
 
                try {
                        $container = $this->getContainer( $fullCont );
@@ -821,16 +833,21 @@ class SwiftFileBackend extends FileBackendStore {
                                }
                        // Recursive: list all files under $dir and its subdirs
                        } else { // files
-                               $files = $container->list_objects( $limit, $after, $prefix );
+                               $objects = $container->list_objects( $limit, $after, $prefix );
+                               $files = $objects;
+                       }
+                       if ( count( $objects ) < $limit ) {
+                               $after = INF; // avoid a second RTT
+                       } else {
+                               $after = end( $objects ); // update last item
                        }
-                       $after = end( $files ); // update last item
-                       reset( $files ); // reset pointer
                } catch ( NoSuchContainerException $e ) {
                } catch ( CloudFilesException $e ) { // some other exception?
                        $this->handleException( $e, null, __METHOD__,
                                array( 'cont' => $fullCont, 'dir' => $dir ) );
                }
 
+               wfProfileOut( __METHOD__ . '-' . $this->name );
                return $files;
        }