From 9b49b048cf7a4bc6f11a4042d12eb7a0c0ebf03c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 11 Jul 2005 00:07:20 +0000 Subject: [PATCH] * Add serialized version number to image metadata cache records --- RELEASE-NOTES | 1 + includes/Image.php | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e03b3eb4d9..f436287d40 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -557,6 +557,7 @@ of MediaWiki:Newpagetext) to &action=edit, if page is new. * Finally fixed Special:Disambiguations that was broke since SCHEMA_WORK * (bug 2761) fix capitalization of "i" in Turkish * (bug 2789) memcached image metadata now cleared after deletion +* Add serialized version number to image metadata cache records === Caveats === diff --git a/includes/Image.php b/includes/Image.php index 01222e2794..02424dc83e 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -15,6 +15,10 @@ if ($wgShowEXIF) require_once('Exif.php'); +/** + * Bump this number when serialized cache records may be incompatible. + */ +define( 'MW_IMAGE_VERSION', 1 ); /** * Class to represent an image @@ -116,7 +120,8 @@ class Image $cachedValues = $wgMemc->get( $keys[0] ); // Check if the key existed and belongs to this version of MediaWiki - if (!empty($cachedValues) && is_array($cachedValues) && isset($cachedValues['width']) + if (!empty($cachedValues) && is_array($cachedValues) + && isset($cachedValues['version']) && ( $cachedValues['version'] == MW_IMAGE_VERSION ) && $cachedValues['fileExists'] && isset( $cachedValues['mime'] ) && isset( $cachedValues['metadata'] ) ) { if ( $wgUseSharedUploads && $cachedValues['fromShared']) { @@ -124,7 +129,11 @@ class Image # in shared repository has not changed if ( isset( $keys[1] ) ) { $commonsCachedValues = $wgMemc->get( $keys[1] ); - if (!empty($commonsCachedValues) && is_array($commonsCachedValues) && isset($commonsCachedValues['mime'])) { + if (!empty($commonsCachedValues) && is_array($commonsCachedValues) + && isset($commonsCachedValues['version']) + && ( $commonsCachedValues['version'] == MW_IMAGE_VERSION ) + && isset($commonsCachedValues['mime'])) { + wfDebug( "Pulling image metadata from shared repository cache\n" ); $this->name = $commonsCachedValues['name']; $this->imagePath = $commonsCachedValues['imagePath']; $this->fileExists = $commonsCachedValues['fileExists']; @@ -140,8 +149,8 @@ class Image $this->imagePath = $this->getFullPath(true); } } - } - else { + } else { + wfDebug( "Pulling image metadata from local cache\n" ); $this->name = $cachedValues['name']; $this->imagePath = $cachedValues['imagePath']; $this->fileExists = $cachedValues['fileExists']; @@ -178,17 +187,19 @@ class Image // We can't cache negative metadata for non-existent files, // because if the file later appears in commons, the local // keys won't be purged. - $cachedValues = array('name' => $this->name, - 'imagePath' => $this->imagePath, - 'fileExists' => $this->fileExists, - 'fromShared' => $this->fromSharedDirectory, - 'width' => $this->width, - 'height' => $this->height, - 'bits' => $this->bits, - 'type' => $this->type, - 'mime' => $this->mime, - 'metadata' => $this->metadata, - 'size' => $this->size); + $cachedValues = array( + 'version' => MW_IMAGE_VERSION, + 'name' => $this->name, + 'imagePath' => $this->imagePath, + 'fileExists' => $this->fileExists, + 'fromShared' => $this->fromSharedDirectory, + 'width' => $this->width, + 'height' => $this->height, + 'bits' => $this->bits, + 'type' => $this->type, + 'mime' => $this->mime, + 'metadata' => $this->metadata, + 'size' => $this->size ); $wgMemc->set( $keys[0], $cachedValues ); } else { -- 2.20.1