From 01b564403e4f12978ad1f941b680633a4eb77952 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 19 May 2013 13:15:50 -0700 Subject: [PATCH] Made SwiftFileBackend::loadObjectListing() populate stat entries in reverse order. Change-Id: I07bf9c852729d65cee72364ca3249e31936d0562 --- includes/filebackend/SwiftFileBackend.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index f9e2ce47d9..54a90d32f5 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -1111,7 +1111,11 @@ class SwiftFileBackend extends FileBackendStore { $names = array(); $storageDir = rtrim( $params['dir'], '/' ); $suffixStart = ( $dir === '' ) ? 0 : strlen( $dir ) + 1; // size of "path/to/dir/" - foreach ( $cfObjects as $object ) { + // Iterate over the list *backwards* as this primes the stat cache, which is LRU. + // If this fills the cache and the caller stats an uncached file before stating + // the ones on the listing, there would be zero cache hits if this went forwards. + for ( end( $cfObjects ); key( $cfObjects ) !== null; prev( $cfObjects ) ) { + $object = current( $cfObjects ); $path = "{$storageDir}/" . substr( $object->name, $suffixStart ); $val = array( // Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT" to TS_MW @@ -1122,7 +1126,7 @@ class SwiftFileBackend extends FileBackendStore { $this->cheapCache->set( $path, 'stat', $val ); $names[] = $object->name; } - return $names; + return array_reverse( $names ); // keep the paths in original order } /** -- 2.20.1