MediaWiki  1.23.14
BacklinkCache Class Reference

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

Public Member Functions

 __construct (Title $title)
 Create a new BacklinkCache. More...
 
 __sleep ()
 Serialization handler, diasallows to serialize the database to prevent failures after this class is deserialized from cache with dead DB connection. More...
 
 clear ()
 Clear locally stored data and database object. 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...
 
 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 (Title $title)
 Create a new BacklinkCache or reuse any existing one. More...
 

Public Attributes

const CACHE_EXPIRY = 3600
 

Protected Member Functions

 getConditions ( $table)
 Get the SQL condition array for selecting backlinks, with a join on the page table. More...
 
 getDB ()
 Get the slave 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...
 
 $fullResultCache = array()
 Contains the whole links from a database result. More...
 
 $partitionCache = array()
 Multi dimensions array representing batches. More...
 
 $title
 Local copy of a Title object. More...
 

Static Protected Attributes

static $cache
 

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 $title->getBacklinkCache().

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

Constructor & Destructor Documentation

◆ __construct()

BacklinkCache::__construct ( Title  $title)

Create a new BacklinkCache.

Parameters
Title$title: Title object to create a backlink cache for

Definition at line 91 of file BacklinkCache.php.

References $title, and title.

Member Function Documentation

◆ __sleep()

BacklinkCache::__sleep ( )

Serialization handler, diasallows to serialize the database to prevent failures after this class is deserialized from cache with dead DB connection.

Returns
array

Definition at line 122 of file BacklinkCache.php.

References array().

◆ clear()

BacklinkCache::clear ( )

Clear locally stored data and database object.

Definition at line 129 of file BacklinkCache.php.

References array().

◆ get()

static BacklinkCache::get ( Title  $title)
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.

Parameters
Title$title: Title object to get a backlink cache for
Returns
BacklinkCache

Definition at line 103 of file BacklinkCache.php.

References $cache, and $title.

Referenced by Title\getBacklinkCache().

◆ getConditions()

BacklinkCache::getConditions (   $table)
protected

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

Parameters
$tableString
Exceptions
MWException
Returns
array|null

Definition at line 274 of file BacklinkCache.php.

References array(), getPrefix(), LIST_OR, title, and wfRunHooks().

Referenced by queryLinks().

◆ getDB()

BacklinkCache::getDB ( )
protected

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

Returns
DatabaseBase object

Definition at line 149 of file BacklinkCache.php.

References $db, DB_SLAVE, and wfGetDB().

Referenced by queryLinks().

◆ getLinks()

BacklinkCache::getLinks (   $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 | INF$max
Returns
TitleArrayFromResult

Definition at line 165 of file BacklinkCache.php.

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

Referenced by getNumLinks().

◆ getNumLinks()

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

Get the approximate number of backlinks.

Parameters
$tableString
$maxinteger|INF Only count up to this many backlinks
Returns
integer

Definition at line 330 of file BacklinkCache.php.

References $count, $wgMemc, getLinks(), global, partition(), title, and wfMemcKey().

Referenced by hasLinks().

◆ getPrefix()

BacklinkCache::getPrefix (   $table)
protected

Get the field name prefix for a given table.

Parameters
$tableString
Exceptions
MWException
Returns
null|string

Definition at line 245 of file BacklinkCache.php.

References array(), and wfRunHooks().

Referenced by getConditions(), and queryLinks().

◆ hasLinks()

BacklinkCache::hasLinks (   $table)

Check if there are any backlinks.

Parameters
$tableString
Returns
bool

Definition at line 320 of file BacklinkCache.php.

References getNumLinks().

◆ 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
$batchSizeInteger
Returns
Array

Definition at line 379 of file BacklinkCache.php.

References $res, $wgMemc, array(), global, list, partitionResult(), queryLinks(), title, wfDebug(), and wfMemcKey().

Referenced by getNumLinks().

◆ partitionResult()

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

Partition a DB result with backlinks in it into batches.

Parameters
$resResultWrapper database result
$batchSizeinteger
$isCompletebool Whether $res includes all the backlinks
Exceptions
MWException
Returns
array

Definition at line 459 of file BacklinkCache.php.

References $res, and array().

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
$tableString
$startIdInteger|false
$endIdInteger|false
$maxInteger|INF
$selectstring 'all' or 'ids'
Returns
ResultWrapper

Definition at line 178 of file BacklinkCache.php.

References $options, $res, array(), getConditions(), getDB(), getPrefix(), wfDebug(), wfProfileIn(), and wfProfileOut().

Referenced by getLinks(), and partition().

◆ setDB()

BacklinkCache::setDB (   $db)

Set the Database object to use.

Parameters
$dbDatabaseBase

Definition at line 140 of file BacklinkCache.php.

References $db.

Member Data Documentation

◆ $cache

BacklinkCache::$cache
staticprotected

Definition at line 46 of file BacklinkCache.php.

◆ $db

BacklinkCache::$db
protected

Local copy of a database object.

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

Definition at line 77 of file BacklinkCache.php.

Referenced by getDB(), and setDB().

◆ $fullResultCache

BacklinkCache::$fullResultCache = array()
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 68 of file BacklinkCache.php.

◆ $partitionCache

BacklinkCache::$partitionCache = array()
protected

Multi dimensions array representing batches.

Keys are:

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

See also
BacklinkCache::partitionResult()

Cleared with BacklinkCache::clear()

Definition at line 59 of file BacklinkCache.php.

◆ $title

BacklinkCache::$title
protected

Local copy of a Title object.

Definition at line 82 of file BacklinkCache.php.

Referenced by __construct(), and get().

◆ CACHE_EXPIRY

const BacklinkCache::CACHE_EXPIRY = 3600

Definition at line 84 of file BacklinkCache.php.


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