MediaWiki
1.28.0
|
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... | |
getCascadeProtectedLinks () | |
Get a Title iterator for cascade-protected template/file use backlinks. 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 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... | |
ResultWrapper[] | $fullResultCache = [] |
Contains the whole links from a database result. More... | |
array[] | $partitionCache = [] |
Multi dimensions array representing batches. More... | |
$title | |
Local copy of a Title object. More... | |
Static Protected Attributes | |
static BacklinkCache | $instance |
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 42 of file BacklinkCache.php.
BacklinkCache::__construct | ( | Title | $title | ) |
Create a new BacklinkCache.
Definition at line 91 of file BacklinkCache.php.
BacklinkCache::__sleep | ( | ) |
Serialization handler, diasallows to serialize the database to prevent failures after this class is deserialized from cache with dead DB connection.
Definition at line 117 of file BacklinkCache.php.
BacklinkCache::clear | ( | ) |
Clear locally stored data and database object.
Definition at line 124 of file BacklinkCache.php.
|
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.
Definition at line 103 of file BacklinkCache.php.
Referenced by Title\getBacklinkCache().
BacklinkCache::getCascadeProtectedLinks | ( | ) |
Get a Title iterator for cascade-protected template/file use backlinks.
Definition at line 492 of file BacklinkCache.php.
References $dbr, $res, as, getDB(), TitleArray\newFromResult(), NS_FILE, and title.
|
protected |
Get the SQL condition array for selecting backlinks, with a join on the page table.
string | $table |
MWException |
Definition at line 266 of file BacklinkCache.php.
References getDB(), getPrefix(), LIST_OR, Hooks\run(), and title.
Referenced by queryLinks().
|
protected |
Get the replica DB connection to the database When non existing, will initialize the connection.
Definition at line 144 of file BacklinkCache.php.
References $db, DB_REPLICA, and wfGetDB().
Referenced by getCascadeProtectedLinks(), getConditions(), and queryLinks().
Get the backlinks for a given table.
Cached in process memory only.
string | $table | |
int | bool | $startId | |
int | bool | $endId | |
int | $max |
Definition at line 160 of file BacklinkCache.php.
References TitleArray\newFromResult(), and queryLinks().
Referenced by getNumLinks().
BacklinkCache::getNumLinks | ( | $table, | |
$max = INF |
|||
) |
Get the approximate number of backlinks.
string | $table | |
int | $max | Only count up to this many backlinks |
Definition at line 322 of file BacklinkCache.php.
References $cache, $count, getLinks(), ObjectCache\getMainWANInstance(), global, partition(), title, and wfMemcKey().
Referenced by hasLinks().
|
protected |
Get the field name prefix for a given table.
string | $table |
MWException |
Definition at line 237 of file BacklinkCache.php.
References Hooks\run().
Referenced by getConditions(), and queryLinks().
BacklinkCache::hasLinks | ( | $table | ) |
Check if there are any backlinks.
string | $table |
Definition at line 312 of file BacklinkCache.php.
References getNumLinks().
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.
string | $table | The links table name |
int | $batchSize |
Definition at line 372 of file BacklinkCache.php.
References $cache, $res, ObjectCache\getMainWANInstance(), list, partitionResult(), queryLinks(), title, wfDebug(), and wfMemcKey().
Referenced by getNumLinks().
|
protected |
Partition a DB result with backlinks in it into batches.
ResultWrapper | $res | Database result |
int | $batchSize | |
bool | $isComplete | Whether $res includes all the backlinks |
MWException |
Definition at line 451 of file BacklinkCache.php.
References $res.
Referenced by partition().
|
protected |
Get the backlinks for a given table.
Cached in process memory only.
string | $table | |
int | bool | $startId | |
int | bool | $endId | |
int | $max | |
string | $select | 'all' or 'ids' |
Definition at line 173 of file BacklinkCache.php.
References $options, $res, getConditions(), getDB(), getPrefix(), and wfDebug().
Referenced by getLinks(), and partition().
BacklinkCache::setDB | ( | $db | ) |
Set the Database object to use.
IDatabase | $db |
Definition at line 135 of file BacklinkCache.php.
References $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.
|
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.
|
staticprotected |
Definition at line 44 of file BacklinkCache.php.
|
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 ]
Cleared with BacklinkCache::clear()
Definition at line 58 of file BacklinkCache.php.
|
protected |
Local copy of a Title object.
Definition at line 82 of file BacklinkCache.php.
Referenced by __construct(), and get().
const BacklinkCache::CACHE_EXPIRY = 3600 |
Definition at line 84 of file BacklinkCache.php.