Cparle has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/403901 )
Change subject: Clear the backlink cache on file delete
......................................................................
Clear the backlink cache on file delete
The backlink cache (and in particular those backlinks
that were cached in memcache) was not being cleared
on page delete, so any backlinks not stored in the cache
when a file was deleted were not being purged.
For files that were duplicates of files on commons,
links to those files on pages are expected to update
to point at commons when the local file is deleted. This
wasn't happening because the relevant backlink pages were
not being purged, leading to broken links. This patch
fixes that.
Bug: T183478
Change-Id: I3bbd79e5a8fa14bf80ceee81e944108edada322e
---
M includes/cache/BacklinkCache.php
M includes/page/WikiPage.php
2 files changed, 40 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/01/403901/1
diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php
index 4341daa..541b60c 100644
--- a/includes/cache/BacklinkCache.php
+++ b/includes/cache/BacklinkCache.php
@@ -28,6 +28,7 @@
use Wikimedia\Rdbms\ResultWrapper;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
/**
* Class for fetching backlink lists, approximate backlink counts and
@@ -122,11 +123,14 @@
}
/**
- * Clear locally stored data and database object.
+ * Clear locally stored data and database object. Invalidate data in
memcache.
*/
public function clear() {
$this->partitionCache = [];
$this->fullResultCache = [];
+ MediaWikiServices::getInstance()
+ ->getMainWANObjectCache()
+ ->touchCheckKey( $this->makeCheckKey() );
unset( $this->db );
}
@@ -344,8 +348,15 @@
);
// 3) ... fallback to memcached ...
- $count = $cache->get( $memcKey );
- if ( $count ) {
+ $curTTL = INF;
+ $count = $cache->get(
+ $memcKey,
+ $curTTL,
+ [
+ $this->makeCheckKey()
+ ]
+ );
+ if ( $count && ( $curTTL > 0 ) ) {
return min( $max, $count );
}
@@ -403,8 +414,15 @@
);
// 3) ... fallback to memcached ...
- $memcValue = $cache->get( $memcKey );
- if ( is_array( $memcValue ) ) {
+ $curTTL = 0;
+ $memcValue = $cache->get(
+ $memcKey,
+ $curTTL,
+ [
+ $this->makeCheckKey()
+ ]
+ );
+ if ( is_array( $memcValue ) && ( $curTTL > 0 ) ) {
$cacheEntry = $memcValue;
wfDebug( __METHOD__ . ": got from memcached $memcKey\n"
);
@@ -444,6 +462,7 @@
$table
);
$cache->set( $memcKey, $cacheEntry['numRows'],
self::CACHE_EXPIRY );
+
wfDebug( __METHOD__ . ": got from database\n" );
@@ -543,4 +562,18 @@
return TitleArray::newFromResult(
new FakeResultWrapper( array_values( $mergedRes ) ) );
}
+
+ /**
+ * Returns check key for the backlinks cache for a particular title
+ *
+ * @return String
+ */
+ private function makeCheckKey() {
+ return MediaWikiServices::getInstance()
+ ->getMainWANObjectCache()
+ ->makeKey(
+ 'backlinks',
+ md5( $this->title->getPrefixedDBkey() )
+ );
+ }
}
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 5029d1d..fa141bd 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3353,6 +3353,8 @@
*/
public static function onArticleDelete( Title $title ) {
// Update existence markers on article/talk tabs...
+ // ... but clear Backlink cache first
+ BacklinkCache::get( $title )->clear();
$other = $title->getOtherPage();
$other->purgeSquid();
--
To view, visit https://gerrit.wikimedia.org/r/403901
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3bbd79e5a8fa14bf80ceee81e944108edada322e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Cparle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits