diff options
author | hmonroy <hmonroy@wikimedia.org> | 2020-04-07 19:41:06 -0700 |
---|---|---|
committer | hmonroy <hmonroy@wikimedia.org> | 2020-04-08 13:16:31 -0700 |
commit | 097c6b575d44848f6531a84c5556a7ca2ab507a7 (patch) | |
tree | 314bda733d66b4542cafe597a237e678e06a51ee /includes/watcheditem | |
parent | e1d49a7113852ce39e9f6f0fb7e2f02524a92373 (diff) | |
download | mediawikicore-097c6b575d44848f6531a84c5556a7ca2ab507a7.tar.gz mediawikicore-097c6b575d44848f6531a84c5556a7ca2ab507a7.zip |
Remove expired items in WatchedItemStore::clearUserWatchedItems
Add functionality to ClearUserWatchedItems function in WatchedItemStore to delete watchlist
expired items from watchlist_expiry table.
Bug: T249283
Change-Id: Ifb475c7b8e824419f45dea489940a15d9edb28c5
Diffstat (limited to 'includes/watcheditem')
-rw-r--r-- | includes/watcheditem/WatchedItemStore.php | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/includes/watcheditem/WatchedItemStore.php b/includes/watcheditem/WatchedItemStore.php index 33b372b08d38..759b85cc8c8b 100644 --- a/includes/watcheditem/WatchedItemStore.php +++ b/includes/watcheditem/WatchedItemStore.php @@ -250,11 +250,37 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac } $dbw = $this->loadBalancer->getConnectionRef( DB_MASTER ); - $dbw->delete( - 'watchlist', - [ 'wl_user' => $user->getId() ], - __METHOD__ - ); + + if ( $this->expiryEnabled ) { + $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ ); + // First fetch the wl_ids. + $wlIds = $dbw->selectFieldValues( 'watchlist', 'wl_id', [ + 'wl_user' => $user->getId() + ] ); + + if ( $wlIds ) { + // Delete rows from both the watchlist and watchlist_expiry tables. + $dbw->delete( + 'watchlist', + [ 'wl_id' => $wlIds ], + __METHOD__ + ); + + $dbw->delete( + 'watchlist_expiry', + [ 'we_item' => $wlIds ], + __METHOD__ + ); + } + $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); + } else { + $dbw->delete( + 'watchlist', + [ 'wl_user' => $user->getId() ], + __METHOD__ + ); + } + $this->uncacheAllItemsForUser( $user ); return true; |