Wikibase
MediaWiki Wikibase extension
Wikibase\Client\Usage\Sql\EntityUsageTable Class Reference

Helper class for updating the wbc_entity_usage table. More...

Public Member Functions

 __construct (EntityIdParser $idParser, IDatabase $writeConnection, int $batchSize=100, ?string $tableName=null, int $addUsagesBatchSize=500)
 
 addUsages (int $pageId, array $usages)
 
 queryUsages (int $pageId)
 
 pruneUsages (int $pageId)
 Removes all usage tracking for a given page. More...
 
 removeUsages (int $pageId, array $usages)
 
 getPagesUsing (array $entityIds, array $aspects=[])
 
 getUnusedEntities (array $entityIds)
 
 setAddUsagesBatchSize (int $addUsagesBatchSize)
 Set the batch size for adding entity usage records. More...
 

Public Attributes

const DEFAULT_TABLE_NAME = 'wbc_entity_usage'
 

Private Member Functions

 getAffectedRowIds (int $pageId, array $usages)
 
 makeUsageRows (int $pageId, array $usages)
 
 getEntityIdStrings (array $entityIds)
 
 convertRowsToUsages (Traversable $rows)
 
 foldRowsIntoPageEntityUsages (Traversable $rows)
 
 getUsedEntityIdStrings (array $idStrings)
 Returns those entity ids which are used from a given set of entity ids. More...
 
 getUsedEntityIdStringsQueries (array $idStrings)
 
 getPrimaryKeys (array $where, string $method)
 Returns the primary keys for the given where clause. More...
 
 getUsedEntityIdStringsMySql (array $subQueries, IDatabase $readConnection)
 

Private Attributes

 $idParser
 
 $writeConnection
 
 $db
 
 $batchSize
 
 $tableName
 
 $addUsagesBatchSize
 
 $logger
 

Detailed Description

Helper class for updating the wbc_entity_usage table.

This is used internally by SqlUsageTracker.

Author
Daniel Kinzler
Marius Hoch

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Client\Usage\Sql\EntityUsageTable::__construct ( EntityIdParser  $idParser,
IDatabase  $writeConnection,
int  $batchSize = 100,
?string  $tableName = null,
int  $addUsagesBatchSize = 500 
)
Parameters
EntityIdParser$idParser
IDatabase$writeConnection
int$batchSizeBatch size for database queries on the entity usage table, including INSERTs, SELECTs, and DELETEs. Defaults to 100.
string | null$tableNamedefaults to wbc_entity_usage
int$addUsagesBatchSizeBatch size for adding entity usage records. Can also be set after construction.
Exceptions
InvalidArgumentException

Member Function Documentation

◆ addUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::addUsages ( int  $pageId,
array  $usages 
)
Parameters
int$pageId
EntityUsage[]$usages
Exceptions
InvalidArgumentException
Returns
int The number of entries added

◆ convertRowsToUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::convertRowsToUsages ( Traversable  $rows)
private
Parameters
Traversable$rows
Returns
EntityUsage[]

◆ foldRowsIntoPageEntityUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::foldRowsIntoPageEntityUsages ( Traversable  $rows)
private
Parameters
Traversable$rows
Returns
PageEntityUsages[]

◆ getAffectedRowIds()

Wikibase\Client\Usage\Sql\EntityUsageTable::getAffectedRowIds ( int  $pageId,
array  $usages 
)
private
Parameters
int$pageId
EntityUsage[]$usages
Returns
int[] affected row ids
Exceptions
DBUnexpectedError
MWException

◆ getEntityIdStrings()

Wikibase\Client\Usage\Sql\EntityUsageTable::getEntityIdStrings ( array  $entityIds)
private
Parameters
EntityId[]$entityIds
Returns
string[]

◆ getPagesUsing()

Wikibase\Client\Usage\Sql\EntityUsageTable::getPagesUsing ( array  $entityIds,
array  $aspects = [] 
)
See also
UsageLookup::getPagesUsing
Parameters
EntityId[]$entityIds
string[]$aspects
Returns
Traversable A traversable over PageEntityUsages grouped by page.

◆ getPrimaryKeys()

Wikibase\Client\Usage\Sql\EntityUsageTable::getPrimaryKeys ( array  $where,
string  $method 
)
private

Returns the primary keys for the given where clause.

Parameters
array$where
string$methodCalling method
Returns
int[]

◆ getUnusedEntities()

Wikibase\Client\Usage\Sql\EntityUsageTable::getUnusedEntities ( array  $entityIds)
See also
UsageLookup::getUnusedEntities
Parameters
EntityId[]$entityIds
Returns
EntityId[]

◆ getUsedEntityIdStrings()

Wikibase\Client\Usage\Sql\EntityUsageTable::getUsedEntityIdStrings ( array  $idStrings)
private

Returns those entity ids which are used from a given set of entity ids.

Parameters
string[]$idStrings
Returns
string[]

◆ getUsedEntityIdStringsMySql()

Wikibase\Client\Usage\Sql\EntityUsageTable::getUsedEntityIdStringsMySql ( array  $subQueries,
IDatabase  $readConnection 
)
private
Parameters
string[]$subQueries
IDatabase$readConnectionmust have type MySQL
Returns
string[]

◆ getUsedEntityIdStringsQueries()

Wikibase\Client\Usage\Sql\EntityUsageTable::getUsedEntityIdStringsQueries ( array  $idStrings)
private
Parameters
string[]$idStrings
Returns
string[]

◆ makeUsageRows()

Wikibase\Client\Usage\Sql\EntityUsageTable::makeUsageRows ( int  $pageId,
array  $usages 
)
private
Parameters
int$pageId
EntityUsage[]$usages
Exceptions
InvalidArgumentException
Returns
array[]

◆ pruneUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::pruneUsages ( int  $pageId)

Removes all usage tracking for a given page.

Parameters
int$pageId
Exceptions
InvalidArgumentException
Returns
EntityUsage[]

◆ queryUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::queryUsages ( int  $pageId)
Parameters
int$pageId
Exceptions
InvalidArgumentException
Returns
EntityUsage[] EntityUsage identity string => EntityUsage

◆ removeUsages()

Wikibase\Client\Usage\Sql\EntityUsageTable::removeUsages ( int  $pageId,
array  $usages 
)
Parameters
int$pageId
EntityUsage[]$usages
Exceptions
InvalidArgumentException

◆ setAddUsagesBatchSize()

Wikibase\Client\Usage\Sql\EntityUsageTable::setAddUsagesBatchSize ( int  $addUsagesBatchSize)

Set the batch size for adding entity usage records.

This can also be set in the constructor.

Parameters
int$addUsagesBatchSize

Member Data Documentation

◆ $addUsagesBatchSize

Wikibase\Client\Usage\Sql\EntityUsageTable::$addUsagesBatchSize
private

◆ $batchSize

Wikibase\Client\Usage\Sql\EntityUsageTable::$batchSize
private

◆ $db

Wikibase\Client\Usage\Sql\EntityUsageTable::$db
private

◆ $idParser

Wikibase\Client\Usage\Sql\EntityUsageTable::$idParser
private

◆ $logger

Wikibase\Client\Usage\Sql\EntityUsageTable::$logger
private

◆ $tableName

Wikibase\Client\Usage\Sql\EntityUsageTable::$tableName
private

◆ $writeConnection

Wikibase\Client\Usage\Sql\EntityUsageTable::$writeConnection
private

◆ DEFAULT_TABLE_NAME

const Wikibase\Client\Usage\Sql\EntityUsageTable::DEFAULT_TABLE_NAME = 'wbc_entity_usage'

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