MediaWiki REL1_31
WatchedItemStore Class Reference

Storage layer class for WatchedItems. More...

Inheritance diagram for WatchedItemStore:
Collaboration diagram for WatchedItemStore:

Public Member Functions

 __construct (LoadBalancer $loadBalancer, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode, $updateRowsPerQuery)
 
 addWatch (User $user, LinkTarget $target)
 
 addWatchBatchForUser (User $user, array $targets)
 
 clearUserWatchedItems (User $user)
 Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist.
 
 clearUserWatchedItemsUsingJobQueue (User $user)
 Queues a job that will clear the users watchlist using the Job Queue.
 
 countUnreadNotifications (User $user, $unreadLimit=null)
 
 countVisitingWatchers (LinkTarget $target, $threshold)
 
 countVisitingWatchersMultiple (array $targetsWithVisitThresholds, $minimumWatchers=null)
 
 countWatchedItems (User $user)
 
 countWatchers (LinkTarget $target)
 
 countWatchersMultiple (array $targets, array $options=[])
 
 duplicateAllAssociatedEntries (LinkTarget $oldTarget, LinkTarget $newTarget)
 
 duplicateEntry (LinkTarget $oldTarget, LinkTarget $newTarget)
 
 getMaxId ()
 
 getNotificationTimestampsBatch (User $user, array $targets)
 
 getWatchedItem (User $user, LinkTarget $target)
 
 getWatchedItemsForUser (User $user, array $options=[])
 
 isWatched (User $user, LinkTarget $target)
 
 loadWatchedItem (User $user, LinkTarget $target)
 
 overrideDeferredUpdatesAddCallableUpdateCallback (callable $callback)
 Overrides the DeferredUpdates::addCallableUpdate callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
 
 overrideRevisionGetTimestampFromIdCallback (callable $callback)
 Overrides the Revision::getTimestampFromId callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
 
 removeWatch (User $user, LinkTarget $target)
 
 resetAllNotificationTimestampsForUser (User $user)
 Reset all watchlist notificaton timestamps for a user using the job queue.
 
 resetNotificationTimestamp (User $user, Title $title, $force='', $oldid=0)
 
 setNotificationTimestampsForUser (User $user, $timestamp, array $targets=[])
 
 setStatsdDataFactory (StatsdDataFactoryInterface $stats)
 
 updateNotificationTimestamp (User $editor, LinkTarget $target, $timestamp)
 

Private Member Functions

 cache (WatchedItem $item)
 
 dbCond (User $user, LinkTarget $target)
 Return an array of conditions to select or update the appropriate database row.
 
 getCached (User $user, LinkTarget $target)
 
 getCacheKey (User $user, LinkTarget $target)
 
 getConnectionRef ( $dbIndex)
 
 getNotificationTimestamp (User $user, Title $title, $item, $force, $oldid)
 
 getVisitingWatchersCondition (IDatabase $db, array $targetsWithVisitThresholds)
 Generates condition for the query used in a batch count visiting watchers.
 
 uncache (User $user, LinkTarget $target)
 
 uncacheAllItemsForUser (User $user)
 
 uncacheLinkTarget (LinkTarget $target)
 
 uncacheUser (User $user)
 

Private Attributes

HashBagOStuff $cache
 
array[] $cacheIndex = []
 Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key' The index is needed so that on mass changes all relevant items can be un-cached.
 
callable null $deferredUpdatesAddCallableUpdateCallback
 
LoadBalancer $loadBalancer
 
ReadOnlyMode $readOnlyMode
 
callable null $revisionGetTimestampFromIdCallback
 
StatsdDataFactoryInterface $stats
 
int $updateRowsPerQuery
 

Additional Inherited Members

- Public Attributes inherited from WatchedItemStoreInterface
const SORT_ASC = 'ASC'
 
const SORT_DESC = 'DESC'
 

Detailed Description

Storage layer class for WatchedItems.

Database interaction & caching TODO caching should be factored out into a CachingWatchedItemStore class

Author
Addshore
Since
1.27

Definition at line 19 of file WatchedItemStore.php.

Constructor & Destructor Documentation

◆ __construct()

WatchedItemStore::__construct ( LoadBalancer $loadBalancer,
HashBagOStuff $cache,
ReadOnlyMode $readOnlyMode,
$updateRowsPerQuery )
Parameters
LoadBalancer$loadBalancer
HashBagOStuff$cache
ReadOnlyMode$readOnlyMode
int$updateRowsPerQuery

Definition at line 70 of file WatchedItemStore.php.

References $cache, $loadBalancer, $readOnlyMode, $updateRowsPerQuery, and cache.

Member Function Documentation

◆ addWatch()

WatchedItemStore::addWatch ( User $user,
LinkTarget $target )
Since
1.27
Parameters
User$user
LinkTarget$target

Implements WatchedItemStoreInterface.

Definition at line 653 of file WatchedItemStore.php.

References addWatchBatchForUser().

◆ addWatchBatchForUser()

WatchedItemStore::addWatchBatchForUser ( User $user,
array $targets )
Since
1.27
Parameters
User$user
LinkTarget[]$targets
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 663 of file WatchedItemStore.php.

References $rows, cache, DB_MASTER, getConnectionRef(), and uncache().

Referenced by addWatch().

◆ cache()

WatchedItemStore::cache ( WatchedItem $item)
private

Definition at line 149 of file WatchedItemStore.php.

References cache, and getCacheKey().

◆ clearUserWatchedItems()

WatchedItemStore::clearUserWatchedItems ( User $user)

Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist.

Since
1.30
Parameters
User$user
Returns
bool true on success, false when too many items are watched

Implements WatchedItemStoreInterface.

Definition at line 234 of file WatchedItemStore.php.

References countWatchedItems(), DB_MASTER, and uncacheAllItemsForUser().

◆ clearUserWatchedItemsUsingJobQueue()

WatchedItemStore::clearUserWatchedItemsUsingJobQueue ( User $user)

Queues a job that will clear the users watchlist using the Job Queue.

Since
1.31
Parameters
User$user

Implements WatchedItemStoreInterface.

Definition at line 281 of file WatchedItemStore.php.

References $job, getMaxId(), ClearUserWatchlistJob\newForUser(), and JobQueueGroup\singleton().

◆ countUnreadNotifications()

WatchedItemStore::countUnreadNotifications ( User $user,
$unreadLimit = null )
Since
1.27
Parameters
User$user
int | null$unreadLimit
Returns
int|bool

Implements WatchedItemStoreInterface.

Definition at line 955 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, and getConnectionRef().

◆ countVisitingWatchers()

WatchedItemStore::countVisitingWatchers ( LinkTarget $target,
$threshold )
Since
1.27
Parameters
LinkTarget$target
string | int$threshold
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 346 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ countVisitingWatchersMultiple()

WatchedItemStore::countVisitingWatchersMultiple ( array $targetsWithVisitThresholds,
$minimumWatchers = null )
Since
1.27
Parameters
array$targetsWithVisitThresholds
int | null$minimumWatchers
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 406 of file WatchedItemStore.php.

References $dbr, $res, DB_REPLICA, getConnectionRef(), getVisitingWatchersCondition(), and list.

◆ countWatchedItems()

WatchedItemStore::countWatchedItems ( User $user)
Since
1.31
Parameters
User$user
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 306 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, and getConnectionRef().

Referenced by clearUserWatchedItems().

◆ countWatchers()

WatchedItemStore::countWatchers ( LinkTarget $target)
Since
1.27
Parameters
LinkTarget$target
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 325 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ countWatchersMultiple()

WatchedItemStore::countWatchersMultiple ( array $targets,
array $options = [] )
Since
1.27
Parameters
LinkTarget[]$targets
array$options
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 370 of file WatchedItemStore.php.

References $dbr, $options, $res, DB_REPLICA, and getConnectionRef().

◆ dbCond()

WatchedItemStore::dbCond ( User $user,
LinkTarget $target )
private

Return an array of conditions to select or update the appropriate database row.

Parameters
User$user
LinkTarget$target
Returns
array

Definition at line 206 of file WatchedItemStore.php.

References MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

Referenced by loadWatchedItem().

◆ duplicateAllAssociatedEntries()

WatchedItemStore::duplicateAllAssociatedEntries ( LinkTarget $oldTarget,
LinkTarget $newTarget )
Since
1.27
Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Implements WatchedItemStoreInterface.

Definition at line 990 of file WatchedItemStore.php.

References duplicateEntry().

◆ duplicateEntry()

WatchedItemStore::duplicateEntry ( LinkTarget $oldTarget,
LinkTarget $newTarget )
Since
1.27
Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Implements WatchedItemStoreInterface.

Definition at line 1003 of file WatchedItemStore.php.

References DB_MASTER, and getConnectionRef().

Referenced by duplicateAllAssociatedEntries().

◆ getCached()

WatchedItemStore::getCached ( User $user,
LinkTarget $target )
private
Parameters
User$user
LinkTarget$target
Returns
WatchedItem|false

Definition at line 193 of file WatchedItemStore.php.

References cache, and getCacheKey().

Referenced by getNotificationTimestampsBatch(), and getWatchedItem().

◆ getCacheKey()

WatchedItemStore::getCacheKey ( User $user,
LinkTarget $target )
private

◆ getConnectionRef()

◆ getMaxId()

WatchedItemStore::getMaxId ( )
Since
1.31
Returns
int The maximum current wl_id

Definition at line 291 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, and getConnectionRef().

Referenced by clearUserWatchedItemsUsingJobQueue().

◆ getNotificationTimestamp()

WatchedItemStore::getNotificationTimestamp ( User $user,
Title $title,
$item,
$force,
$oldid )
private

Definition at line 902 of file WatchedItemStore.php.

References getNotificationTimestamp(), and loadWatchedItem().

Referenced by getNotificationTimestamp().

◆ getNotificationTimestampsBatch()

WatchedItemStore::getNotificationTimestampsBatch ( User $user,
array $targets )
Since
1.27
Parameters
User$user
LinkTarget[]$targets
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 602 of file WatchedItemStore.php.

References $dbr, $res, DB_REPLICA, getCached(), getConnectionRef(), and wfTimestampOrNull().

◆ getVisitingWatchersCondition()

WatchedItemStore::getVisitingWatchersCondition ( IDatabase $db,
array $targetsWithVisitThresholds )
private

Generates condition for the query used in a batch count visiting watchers.

Parameters
IDatabase$db
array$targetsWithVisitThresholdsarray of pairs (LinkTarget, last visit threshold)
Returns
string

Definition at line 451 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\addQuotes(), list, LIST_AND, LIST_OR, Wikimedia\Rdbms\IDatabase\makeList(), and Wikimedia\Rdbms\IDatabase\timestamp().

Referenced by countVisitingWatchersMultiple().

◆ getWatchedItem()

WatchedItemStore::getWatchedItem ( User $user,
LinkTarget $target )
Since
1.27
Parameters
User$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 494 of file WatchedItemStore.php.

References getCached(), and loadWatchedItem().

Referenced by isWatched().

◆ getWatchedItemsForUser()

WatchedItemStore::getWatchedItemsForUser ( User $user,
array $options = [] )
Since
1.27
Parameters
User$user
array$options
Returns
WatchedItem[]

Implements WatchedItemStoreInterface.

Definition at line 548 of file WatchedItemStore.php.

References $options, $res, DB_MASTER, DB_REPLICA, false, and getConnectionRef().

◆ isWatched()

WatchedItemStore::isWatched ( User $user,
LinkTarget $target )
Since
1.27
Parameters
User$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 592 of file WatchedItemStore.php.

References getWatchedItem().

◆ loadWatchedItem()

WatchedItemStore::loadWatchedItem ( User $user,
LinkTarget $target )
Since
1.27
Parameters
User$user
LinkTarget$target
Returns
WatchedItem|bool

Implements WatchedItemStoreInterface.

Definition at line 514 of file WatchedItemStore.php.

References $dbr, cache, DB_REPLICA, dbCond(), getConnectionRef(), and wfTimestampOrNull().

Referenced by getNotificationTimestamp(), getWatchedItem(), and resetNotificationTimestamp().

◆ overrideDeferredUpdatesAddCallableUpdateCallback()

WatchedItemStore::overrideDeferredUpdatesAddCallableUpdateCallback ( callable $callback)

Overrides the DeferredUpdates::addCallableUpdate callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Parameters
callable$callback
See also
DeferredUpdates::addCallableUpdate for callback signiture
Returns
ScopedCallback to reset the overridden value
Exceptions
MWException

Definition at line 105 of file WatchedItemStore.php.

References $deferredUpdatesAddCallableUpdateCallback.

◆ overrideRevisionGetTimestampFromIdCallback()

WatchedItemStore::overrideRevisionGetTimestampFromIdCallback ( callable $callback)

Overrides the Revision::getTimestampFromId callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Parameters
callable$callback
See also
Revision::getTimestampFromId for callback signiture
Returns
ScopedCallback to reset the overridden value
Exceptions
MWException

Definition at line 128 of file WatchedItemStore.php.

References $revisionGetTimestampFromIdCallback.

◆ removeWatch()

WatchedItemStore::removeWatch ( User $user,
LinkTarget $target )
Since
1.27
Parameters
User$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 715 of file WatchedItemStore.php.

References $success, DB_MASTER, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getNamespace(), and uncache().

◆ resetAllNotificationTimestampsForUser()

WatchedItemStore::resetAllNotificationTimestampsForUser ( User $user)

Reset all watchlist notificaton timestamps for a user using the job queue.

Since
1.31
Parameters
User$userThe user to reset the timestamps for

Implements WatchedItemStoreInterface.

Definition at line 773 of file WatchedItemStore.php.

References $job.

◆ resetNotificationTimestamp()

WatchedItemStore::resetNotificationTimestamp ( User $user,
Title $title,
$force = '',
$oldid = 0 )
Since
1.27
Parameters
User$user
Title$title
string$force
int$oldid
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 863 of file WatchedItemStore.php.

References $job, loadWatchedItem(), and uncache().

◆ setNotificationTimestampsForUser()

WatchedItemStore::setNotificationTimestampsForUser ( User $user,
$timestamp,
array $targets = [] )
Since
1.27
Parameters
User$user
string | int$timestamp
LinkTarget[]$targets
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 743 of file WatchedItemStore.php.

References $batch, $success, DB_MASTER, getConnectionRef(), and uncacheUser().

◆ setStatsdDataFactory()

WatchedItemStore::setStatsdDataFactory ( StatsdDataFactoryInterface $stats)
Parameters
StatsdDataFactoryInterface$stats

Implements StatsdAwareInterface.

Definition at line 90 of file WatchedItemStore.php.

References $stats.

◆ uncache()

WatchedItemStore::uncache ( User $user,
LinkTarget $target )
private

◆ uncacheAllItemsForUser()

WatchedItemStore::uncacheAllItemsForUser ( User $user)
private

Definition at line 250 of file WatchedItemStore.php.

References cache.

Referenced by clearUserWatchedItems().

◆ uncacheLinkTarget()

WatchedItemStore::uncacheLinkTarget ( LinkTarget $target)
private

◆ uncacheUser()

WatchedItemStore::uncacheUser ( User $user)
private

Definition at line 175 of file WatchedItemStore.php.

References cache.

Referenced by setNotificationTimestampsForUser().

◆ updateNotificationTimestamp()

WatchedItemStore::updateNotificationTimestamp ( User $editor,
LinkTarget $target,
$timestamp )
Since
1.27
Parameters
User$editor
LinkTarget$target
string | int$timestamp
Returns
int[]

Implements WatchedItemStoreInterface.

Definition at line 802 of file WatchedItemStore.php.

References $editor, $fname, $wgUpdateRowsPerQuery, DB_MASTER, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getNamespace(), and uncacheLinkTarget().

Member Data Documentation

◆ $cache

HashBagOStuff WatchedItemStore::$cache
private

Definition at line 34 of file WatchedItemStore.php.

Referenced by __construct().

◆ $cacheIndex

array [] WatchedItemStore::$cacheIndex = []
private

Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key' The index is needed so that on mass changes all relevant items can be un-cached.

For example: Clearing a users watchlist of all items or updating notification timestamps for all users watching a single target.

Definition at line 42 of file WatchedItemStore.php.

◆ $deferredUpdatesAddCallableUpdateCallback

callable null WatchedItemStore::$deferredUpdatesAddCallableUpdateCallback
private

◆ $loadBalancer

LoadBalancer WatchedItemStore::$loadBalancer
private

Definition at line 24 of file WatchedItemStore.php.

Referenced by __construct().

◆ $readOnlyMode

ReadOnlyMode WatchedItemStore::$readOnlyMode
private

Definition at line 29 of file WatchedItemStore.php.

Referenced by __construct().

◆ $revisionGetTimestampFromIdCallback

callable null WatchedItemStore::$revisionGetTimestampFromIdCallback
private

Definition at line 52 of file WatchedItemStore.php.

Referenced by overrideRevisionGetTimestampFromIdCallback().

◆ $stats

StatsdDataFactoryInterface WatchedItemStore::$stats
private

Definition at line 62 of file WatchedItemStore.php.

Referenced by setStatsdDataFactory().

◆ $updateRowsPerQuery

int WatchedItemStore::$updateRowsPerQuery
private

Definition at line 57 of file WatchedItemStore.php.

Referenced by __construct().


The documentation for this class was generated from the following file: