MediaWiki master
MediaWiki\Cache\BacklinkCache Class Reference

Class for fetching backlink lists, approximate backlink counts and partitions. More...

Collaboration diagram for MediaWiki\Cache\BacklinkCache:

Public Member Functions

 __construct (ServiceOptions $options, LinksMigration $linksMigration, WANObjectCache $wanCache, HookContainer $hookContainer, IConnectionProvider $dbProvider, PageReference $page)
 Create a new BacklinkCache.
 
 getCascadeProtectedLinkPages ()
 Get a PageIdentity iterator for cascade-protected template/file use backlinks.
 
 getLinkPages (string $table, $startId=false, $endId=false, $max=INF)
 Get the backlinks for a given table.
 
 getNumLinks ( $table, $max=INF)
 Get the approximate number of backlinks.
 
 getPage ()
 
 hasLinks ( $table)
 Check if there are any backlinks.
 
 partition ( $table, $batchSize)
 Partition the backlinks into batches.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Protected Member Functions

 getDB ()
 Get the replica DB connection to the database.
 
 getPrefix ( $table)
 Get the field name prefix for a given table.
 
 partitionResult ( $res, $batchSize, $isComplete=true)
 Partition a DB result with backlinks in it into batches.
 
 queryLinks ( $table, $startId, $endId, $max, $select='all')
 Get the backlinks for a given table.
 

Protected Attributes

IResultWrapper[] $fullResultCache = []
 Contains the whole links from a database result.
 
PageReference $page
 Local copy of a PageReference object.
 
array[] $partitionCache = []
 Multi dimensions array representing batches.
 
WANObjectCache $wanCache
 

Detailed Description

Class for fetching backlink lists, approximate backlink counts and partitions.

This is a shared cache.

Instances of this class should typically be fetched with the method ::getBacklinkCache() from the BacklinkCacheFactory service.

Ideally you should only get your backlinks from here when you think there is some advantage in caching them. Otherwise, it's just a waste of memory.

Introduced by r47317

Definition at line 64 of file BacklinkCache.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Cache\BacklinkCache::__construct ( ServiceOptions $options,
LinksMigration $linksMigration,
WANObjectCache $wanCache,
HookContainer $hookContainer,
IConnectionProvider $dbProvider,
PageReference $page )

Create a new BacklinkCache.

Parameters
ServiceOptions$options
LinksMigration$linksMigration
WANObjectCache$wanCache
HookContainer$hookContainer
IConnectionProvider$dbProvider
PageReference$pagePage to create a backlink cache for

Definition at line 121 of file BacklinkCache.php.

References MediaWiki\Cache\BacklinkCache\$page, MediaWiki\Cache\BacklinkCache\$wanCache, and MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ getCascadeProtectedLinkPages()

MediaWiki\Cache\BacklinkCache::getCascadeProtectedLinkPages ( )

Get a PageIdentity iterator for cascade-protected template/file use backlinks.

Returns
Iterator<PageIdentity>
Since
1.37

Definition at line 506 of file BacklinkCache.php.

◆ getDB()

MediaWiki\Cache\BacklinkCache::getDB ( )
protected

Get the replica DB connection to the database.

Returns
IReadableDatabase

Definition at line 151 of file BacklinkCache.php.

◆ getLinkPages()

MediaWiki\Cache\BacklinkCache::getLinkPages ( string $table,
$startId = false,
$endId = false,
$max = INF )

Get the backlinks for a given table.

Cached in process memory only.

Parameters
string$table
int | bool$startId
int | bool$endId
int | float$maxInteger, or INF for no max
Returns
Iterator<PageIdentity>
Since
1.37

Definition at line 164 of file BacklinkCache.php.

◆ getNumLinks()

MediaWiki\Cache\BacklinkCache::getNumLinks ( $table,
$max = INF )

Get the approximate number of backlinks.

Parameters
string$table
int | float$maxOnly count up to this many backlinks, or INF for no max
Returns
int

Definition at line 348 of file BacklinkCache.php.

References getDB().

◆ getPage()

MediaWiki\Cache\BacklinkCache::getPage ( )
Since
1.37
Returns
PageReference

Definition at line 142 of file BacklinkCache.php.

◆ getPrefix()

MediaWiki\Cache\BacklinkCache::getPrefix ( $table)
protected

Get the field name prefix for a given table.

Parameters
string$table
Returns
null|string

Definition at line 227 of file BacklinkCache.php.

◆ hasLinks()

MediaWiki\Cache\BacklinkCache::hasLinks ( $table)

Check if there are any backlinks.

Parameters
string$table
Returns
bool

Definition at line 338 of file BacklinkCache.php.

◆ partition()

MediaWiki\Cache\BacklinkCache::partition ( $table,
$batchSize )

Partition the backlinks into batches.

Returns an array giving the start and end of each range. The first batch has a start of false, and the last batch has an end of false.

Parameters
string$tableThe links table name
int$batchSize
Returns
array

Definition at line 400 of file BacklinkCache.php.

References getDB(), and wfDebug().

◆ partitionResult()

MediaWiki\Cache\BacklinkCache::partitionResult ( $res,
$batchSize,
$isComplete = true )
protected

Partition a DB result with backlinks in it into batches.

Parameters
IResultWrapper$resDatabase result
int$batchSize
bool$isCompleteWhether $res includes all the backlinks
Returns
array

Definition at line 465 of file BacklinkCache.php.

◆ queryLinks()

MediaWiki\Cache\BacklinkCache::queryLinks ( $table,
$startId,
$endId,
$max,
$select = 'all' )
protected

Get the backlinks for a given table.

Cached in process memory only.

Parameters
string$table
int | bool$startId
int | bool$endId
int$max
string$select'all' or 'ids'
Returns
IResultWrapper

Definition at line 182 of file BacklinkCache.php.

References getDB(), and wfDebug().

Member Data Documentation

◆ $fullResultCache

IResultWrapper [] MediaWiki\Cache\BacklinkCache::$fullResultCache = []
protected

Contains the whole links from a database result.

This is raw data that will be partitioned in $partitionCache

Initialized with BacklinkCache::queryLinks()

Definition at line 92 of file BacklinkCache.php.

◆ $page

PageReference MediaWiki\Cache\BacklinkCache::$page
protected

Local copy of a PageReference object.

Definition at line 104 of file BacklinkCache.php.

Referenced by MediaWiki\Cache\BacklinkCache\__construct().

◆ $partitionCache

array [] MediaWiki\Cache\BacklinkCache::$partitionCache = []
protected

Multi dimensions array representing batches.

Keys are:

‍(string) links table name (int) batch size 'numRows' : Number of rows for this link table 'batches' : [ $start, $end ]

See also
BacklinkCache::partitionResult()

Definition at line 82 of file BacklinkCache.php.

◆ $wanCache

WANObjectCache MediaWiki\Cache\BacklinkCache::$wanCache
protected

Definition at line 95 of file BacklinkCache.php.

Referenced by MediaWiki\Cache\BacklinkCache\__construct().

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Cache\BacklinkCache::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const UpdateRowsPerJob
Name constant for the UpdateRowsPerJob setting, for use with Config::get()
Access: internal
Used by ServiceWiring.php

Definition at line 68 of file BacklinkCache.php.


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