MediaWiki  master
BacklinkCache Class Reference

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

Collaboration diagram for BacklinkCache:

Public Member Functions

 __construct (WANObjectCache $wanCache, PageReference $page)
 Create a new BacklinkCache. More...
 
 clear ()
 Clear locally stored data and database object. More...
 
 getCascadeProtectedLinkPages ()
 Get a PageIdentity iterator for cascade-protected template/file use backlinks. More...
 
 getCascadeProtectedLinks ()
 Get a Title iterator for cascade-protected template/file use backlinks. More...
 
 getLinkPages (string $table, $startId=false, $endId=false, $max=INF)
 Get the backlinks for a given table. More...
 
 getLinks ( $table, $startId=false, $endId=false, $max=INF)
 Get the backlinks for a given table. More...
 
 getNumLinks ( $table, $max=INF)
 Get the approximate number of backlinks. More...
 
 getPage ()
 
 hasLinks ( $table)
 Check if there are any backlinks. More...
 
 partition ( $table, $batchSize)
 Partition the backlinks into batches. More...
 
 setDB ( $db)
 Set the Database object to use. More...
 

Static Public Member Functions

static get (PageReference $page)
 Create a new BacklinkCache or reuse any existing one. More...
 

Protected Member Functions

 getConditions ( $table)
 Get the SQL condition array for selecting backlinks, with a join on the page table. More...
 
 getDB ()
 Get the replica DB connection to the database When non existing, will initialize the connection. More...
 
 getPrefix ( $table)
 Get the field name prefix for a given table. More...
 
 partitionResult ( $res, $batchSize, $isComplete=true)
 Partition a DB result with backlinks in it into batches. More...
 
 queryLinks ( $table, $startId, $endId, $max, $select='all')
 Get the backlinks for a given table. More...
 

Protected Attributes

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

Static Protected Attributes

static BacklinkCache $instance
 

Private Member Functions

 getCascadeProtectedLinksInternal ()
 Get an array of cascade-protected template/file use backlinks. More...
 
 makeCheckKey ()
 Returns check key for the backlinks cache for a particular title. More...
 

Private Attributes

const CACHE_EXPIRY = 3600
 

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 50 of file BacklinkCache.php.

Constructor & Destructor Documentation

◆ __construct()

BacklinkCache::__construct ( WANObjectCache  $wanCache,
PageReference  $page 
)

Create a new BacklinkCache.

Parameters
WANObjectCache$wanCache
PageReference$pagePage to create a backlink cache for

Definition at line 106 of file BacklinkCache.php.

References $page, and $wanCache.

Member Function Documentation

◆ clear()

BacklinkCache::clear ( )

Clear locally stored data and database object.

Invalidate data in memcache.

Definition at line 138 of file BacklinkCache.php.

References makeCheckKey().

◆ get()

static BacklinkCache::get ( PageReference  $page)
static

Create a new BacklinkCache or reuse any existing one.

Currently, only one cache instance can exist; callers that need multiple backlink cache objects should keep them in scope.

Deprecated:
since 1.37 Use BacklinkCacheFactory::getBacklinkCache() instead
Parameters
PageReference$pagePage to get a backlink cache for
Returns
BacklinkCache

Definition at line 121 of file BacklinkCache.php.

References $page.

◆ getCascadeProtectedLinkPages()

BacklinkCache::getCascadeProtectedLinkPages ( )

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

Returns
Iterator Iterator of PageIdentity objects
Since
1.37

Definition at line 548 of file BacklinkCache.php.

References getCascadeProtectedLinksInternal().

◆ getCascadeProtectedLinks()

BacklinkCache::getCascadeProtectedLinks ( )

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

Deprecated:
since 1.37, use getCascadeProtectedLinkPages()
Returns
TitleArray
Since
1.25

Definition at line 564 of file BacklinkCache.php.

References getCascadeProtectedLinksInternal(), and TitleArray\newFromResult().

◆ getCascadeProtectedLinksInternal()

BacklinkCache::getCascadeProtectedLinksInternal ( )
private

Get an array of cascade-protected template/file use backlinks.

Returns
stdClass[]

Definition at line 574 of file BacklinkCache.php.

References $dbr, $res, getDB(), and NS_FILE.

Referenced by getCascadeProtectedLinkPages(), and getCascadeProtectedLinks().

◆ getConditions()

BacklinkCache::getConditions (   $table)
protected

Get the SQL condition array for selecting backlinks, with a join on the page table.

Parameters
string$table
Exceptions
MWException
Returns
array|null

Definition at line 301 of file BacklinkCache.php.

References Title\castFromPageReference(), getDB(), getPrefix(), and LIST_OR.

Referenced by queryLinks().

◆ getDB()

BacklinkCache::getDB ( )
protected

Get the replica DB connection to the database When non existing, will initialize the connection.

Returns
IDatabase

Definition at line 159 of file BacklinkCache.php.

References $db, DB_REPLICA, and wfGetDB().

Referenced by getCascadeProtectedLinksInternal(), getConditions(), and queryLinks().

◆ getLinkPages()

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 Iterator of PageIdentity objects
Since
1.37

Definition at line 176 of file BacklinkCache.php.

References queryLinks().

Referenced by getNumLinks().

◆ getLinks()

BacklinkCache::getLinks (   $table,
  $startId = false,
  $endId = false,
  $max = INF 
)

Get the backlinks for a given table.

Cached in process memory only.

Deprecated:
in 1.37, use getLinkPages()
Parameters
string$table
int | bool$startId
int | bool$endId
int$max
Returns
TitleArrayFromResult

Definition at line 197 of file BacklinkCache.php.

References TitleArray\newFromResult(), and queryLinks().

◆ getNumLinks()

BacklinkCache::getNumLinks (   $table,
  $max = INF 
)

Get the approximate number of backlinks.

Parameters
string$table
int$maxOnly count up to this many backlinks
Returns
int

Definition at line 358 of file BacklinkCache.php.

References $wgUpdateRowsPerJob, getLinkPages(), makeCheckKey(), and partition().

Referenced by hasLinks().

◆ getPage()

BacklinkCache::getPage ( )
Since
1.37
Returns
PageReference

Definition at line 131 of file BacklinkCache.php.

References $page.

◆ getPrefix()

BacklinkCache::getPrefix (   $table)
protected

Get the field name prefix for a given table.

Parameters
string$table
Exceptions
MWException
Returns
null|string

Definition at line 272 of file BacklinkCache.php.

Referenced by getConditions(), and queryLinks().

◆ hasLinks()

BacklinkCache::hasLinks (   $table)

Check if there are any backlinks.

Parameters
string$table
Returns
bool

Definition at line 348 of file BacklinkCache.php.

References getNumLinks().

◆ makeCheckKey()

BacklinkCache::makeCheckKey ( )
private

Returns check key for the backlinks cache for a particular title.

Returns
string

Definition at line 625 of file BacklinkCache.php.

Referenced by clear(), getNumLinks(), and partition().

◆ partition()

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 418 of file BacklinkCache.php.

References $res, makeCheckKey(), partitionResult(), queryLinks(), and wfDebug().

Referenced by getNumLinks().

◆ partitionResult()

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
Exceptions
MWException
Returns
array

Definition at line 507 of file BacklinkCache.php.

References $res.

Referenced by partition().

◆ queryLinks()

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 210 of file BacklinkCache.php.

References $res, getConditions(), getDB(), getPrefix(), and wfDebug().

Referenced by getLinkPages(), getLinks(), and partition().

◆ setDB()

BacklinkCache::setDB (   $db)

Set the Database object to use.

Parameters
IDatabase$db

Definition at line 150 of file BacklinkCache.php.

References $db.

Member Data Documentation

◆ $db

BacklinkCache::$db
protected

Local copy of a database object.

Accessor: BacklinkCache::getDB() Mutator : BacklinkCache::setDB() Cleared with BacklinkCache::clear()

Definition at line 90 of file BacklinkCache.php.

Referenced by getDB(), and setDB().

◆ $fullResultCache

IResultWrapper [] BacklinkCache::$fullResultCache = []
protected

Contains the whole links from a database result.

This is raw data that will be partitioned in $partitionCache

Initialized with BacklinkCache::getLinks() Cleared with BacklinkCache::clear()

Definition at line 78 of file BacklinkCache.php.

◆ $instance

BacklinkCache BacklinkCache::$instance
staticprotected

Definition at line 54 of file BacklinkCache.php.

◆ $page

PageReference BacklinkCache::$page
protected

Local copy of a PageReference object.

Definition at line 96 of file BacklinkCache.php.

Referenced by __construct(), get(), and getPage().

◆ $partitionCache

array [] 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()

Cleared with BacklinkCache::clear()

Definition at line 68 of file BacklinkCache.php.

◆ $wanCache

WANObjectCache BacklinkCache::$wanCache
protected

Definition at line 81 of file BacklinkCache.php.

Referenced by __construct().

◆ CACHE_EXPIRY

const BacklinkCache::CACHE_EXPIRY = 3600
private

Definition at line 98 of file BacklinkCache.php.


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