Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276450

Change subject: Uncache things in WatchedItemStore::updateNotificationTimestamp
......................................................................

Uncache things in WatchedItemStore::updateNotificationTimestamp

When the notification timestamp for a LinkTarget is
updated all items relating to that LinkTarget should
be uncached!..

Change-Id: I5dc58e018a6a4a15903abc1e0b326b4220abc75e
---
M includes/WatchedItemStore.php
M tests/phpunit/includes/WatchedItemStoreIntegrationTest.php
2 files changed, 20 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/276450/1

diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 1aed8e0..5b5d8e2 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -23,6 +23,11 @@
        private $cache;
 
        /**
+        * @var array[] Looks like $cacheLinkTargetIndex[namespace ID][DB Key][ 
'key1', 'key2' ]
+        */
+       private $cacheLinkTargetIndex = [];
+
+       /**
         * @var callable|null
         */
        private $deferredUpdatesAddCallableUpdateCallback;
@@ -121,14 +126,23 @@
        }
 
        private function cache( WatchedItem $item ) {
-               $this->cache->set(
-                       $this->getCacheKey( $item->getUser(), 
$item->getLinkTarget() ),
-                       $item
-               );
+               $linkTarget = $item->getLinkTarget();
+               $key = $this->getCacheKey( $item->getUser(), $linkTarget );
+               $this->cache->set( $key, $item );
+               
$this->cacheLinkTargetIndex[$linkTarget->getNamespace()][$linkTarget->getDBkey()][]
 = $key;
        }
 
        private function uncache( User $user, LinkTarget $target ) {
                $this->cache->delete( $this->getCacheKey( $user, $target ) );
+       }
+
+       private function uncacheLinkTarget( LinkTarget $target ) {
+               if( !isset( 
$this->cacheLinkTargetIndex[$target->getNamespace()][$target->getDBkey()] ) ) {
+                       return;
+               }
+               foreach ( 
$this->cacheLinkTargetIndex[$target->getNamespace()][$target->getDBkey()] as 
$key ) {
+                       $this->cache->delete( $key );
+               }
        }
 
        /**
@@ -350,6 +364,7 @@
                                                        'wl_title' => 
$target->getDBkey(),
                                                ], $fname
                                        );
+                                       $this->uncacheLinkTarget( $target );
                                }
                        );
                }
diff --git a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php 
b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php
index 9341fb8..e2ab512 100644
--- a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php
+++ b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php
@@ -57,7 +57,7 @@
                );
 
                $this->assertTrue( $store->resetNotificationTimestamp( $user, 
$title ) );
-               $this->assertNull( $store->loadWatchedItem( $user, $title 
)->getNotificationTimestamp() );
+               $this->assertNull( $store->getWatchedItem( $user, $title 
)->getNotificationTimestamp() );
        }
 
        public function testDuplicateAllAssociatedEntries() {

-- 
To view, visit https://gerrit.wikimedia.org/r/276450
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5dc58e018a6a4a15903abc1e0b326b4220abc75e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to