From 3589fc100b0534046a77ded2f6f4cbc6ede70ed0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 31 Dec 2012 16:36:02 -0800 Subject: [PATCH] Avoid caching empty directory lists. Change-Id: I574043a240018043126e2b1b05b08bf7e23610d6 --- FancyCaptcha.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/FancyCaptcha.class.php b/FancyCaptcha.class.php index f559f0f3c..6b19cdbba 100644 --- a/FancyCaptcha.class.php +++ b/FancyCaptcha.class.php @@ -159,7 +159,7 @@ class FancyCaptcha extends SimpleCaptcha { $key = "fancycaptcha:dirlist:{$backend->getWikiId()}:" . sha1( $directory ); $dirs = $wgMemc->get( $key ); // check cache - if ( !is_array( $dirs ) ) { // cache miss + if ( !is_array( $dirs ) || !count( $dirs ) ) { // cache miss $dirs = array(); // subdirs actually present... foreach ( $backend->getTopDirectoryList( array( 'dir' => $directory ) ) as $entry ) { if ( ctype_xdigit( $entry ) && strlen( $entry ) == 1 ) { @@ -167,7 +167,9 @@ class FancyCaptcha extends SimpleCaptcha { } } wfDebug( "Cache miss for $directory subdirectory listing.\n" ); - $wgMemc->set( $key, $dirs, 86400 ); + if ( count( $dirs ) ) { + $wgMemc->set( $key, $dirs, 86400 ); + } } if ( !count( $dirs ) ) { @@ -204,7 +206,7 @@ class FancyCaptcha extends SimpleCaptcha { $key = "fancycaptcha:filelist:{$backend->getWikiId()}:" . sha1( $directory ); $files = $wgMemc->get( $key ); // check cache - if ( !is_array( $files ) ) { // cache miss + if ( !is_array( $files ) || !count( $files ) ) { // cache miss $files = array(); // captcha files foreach ( $backend->getTopFileList( array( 'dir' => $directory ) ) as $entry ) { $files[] = $entry; @@ -213,7 +215,9 @@ class FancyCaptcha extends SimpleCaptcha { break; } } - $wgMemc->set( $key, $files, 86400 ); + if ( count( $files ) ) { + $wgMemc->set( $key, $files, 86400 ); + } wfDebug( "Cache miss for $directory captcha listing.\n" ); }