From bfc45cd804a46971de9bb77ca441324a4d0d9e69 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 1 Mar 2006 03:53:33 +0000 Subject: [PATCH] Invalidate image description page cache when the list of links changes --- includes/LinksUpdate.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index bcfb0c340f..419d3d60f1 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -83,6 +83,10 @@ class LinksUpdate { $this->incrTableUpdate( 'imagelinks', 'il', $this->getImageDeletions( $existing ), $this->getImageInsertions( $existing ) ); + # Invalidate all image description pages which had links added or removed + $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing ); + $this->invalidateImageDescriptions( $imageUpdates ); + # External links $existing = $this->getExistingExternals(); $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ), @@ -107,9 +111,7 @@ class LinksUpdate { $this->incrTableUpdate( 'categorylinks', 'cl', $this->getCategoryDeletions( $existing ), $this->getCategoryInsertions( $existing ) ); - # I think this works out to a set XOR operation, the idea is to invalidate all - # categories which were added, deleted or changed - # FIXME: surely there's a more appropriate place to put this update? + # Invalidate all categories which were added, deleted or changed (set symmetric difference) $categoryUpdates = array_diff_assoc( $existing, $this->mCategories ) + array_diff_assoc( $this->mCategories, $existing ); $this->invalidateCategories( $categoryUpdates ); @@ -125,9 +127,11 @@ class LinksUpdate { $fname = 'LinksUpdate::doDumbUpdate'; wfProfileIn( $fname ); - # Refresh category pages + # Refresh category pages and image description pages $existing = $this->getExistingCategories(); $categoryUpdates = array_diff_assoc( $existing, $this->mCategories ) + array_diff_assoc( $this->mCategories, $existing ); + $existing = $this->getExistingImages(); + $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing ); # Refresh links of all pages including this page if ( $this->mRecursive ) { @@ -144,8 +148,9 @@ class LinksUpdate { $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' ); $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' ); - # Update the cache of all the category pages + # Update the cache of all the category pages and image description pages which were changed $this->invalidateCategories( $categoryUpdates ); + $this->invalidateImageDescriptions( $imageUpdates ); wfProfileOut( $fname ); } @@ -162,6 +167,18 @@ class LinksUpdate { } } + function invalidateImageDescriptions( $images ) { + $fname = 'LinksUpdate::invalidateImageDescriptions'; + if ( count( $images ) ) { + $this->mDb->update( 'page', array( 'page_touched' => $this->mDb->timestamp() ), + array( + 'page_namespace' => NS_IMAGE, + 'page_title IN (' . $this->mDb->makeList( array_keys( $images ) ) . ')' + ), $fname + ); + } + } + function dumbTableUpdate( $table, $insertions, $fromField ) { $fname = 'LinksUpdate::dumbTableUpdate'; $this->mDb->delete( $table, array( $fromField => $this->mId ), $fname ); -- 2.20.1