Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Client\Store\Sql\BulkSubscriptionUpdater Class Reference

Implements bulk updates for the repo's wb_changes_subscription table, based on the client's local wbc_entity_usage table. More...

Public Member Functions

 __construct (ClientDomainDb $clientDb, RepoDomainDb $repoDb, string $subscriberWikiId, int $batchSize=1000)
 
 setProgressReporter (MessageReporter $progressReporter)
 
 updateSubscriptions (EntityId $startEntity=null)
 Insert subscriptions based on entries in wbc_entity_usage.
 
 purgeSubscriptions (EntityId $startEntity=null)
 Remove subscriptions for entities not present in in wbc_entity_usage.
 

Private Member Functions

 processUpdateBatch (array &$continuation=null)
 
 insertUpdateBatch (array $entities)
 
 getUpdateBatch (array &$continuation=null)
 
 makeSubscriptionRows (array $entities)
 Returns a list of rows for insertion, using DatabaseBase's multi-row insert mechanism.
 
 getEntityIdsFromRows (IResultWrapper $res, $entityIdField, array &$continuation=null)
 Extracts entity id strings from the rows in a query result, and updates $continuation to a position "after" the content of the given query result.
 
 processDeletionBatch (array &$continuation=null)
 
 getDeletionRange (array &$continuation=null)
 Returns a range of entity IDs to delete, based on this updater's batch size.
 
 deleteSubscriptionRange (string $minId, string $maxId)
 Deletes a range of subscriptions.
 

Private Attributes

 $localConnectionManager
 
 $repoConnectionManager
 
 $subscriberWikiId
 
 $repoDb
 
 $batchSize
 
 $progressReporter
 

Detailed Description

Implements bulk updates for the repo's wb_changes_subscription table, based on the client's local wbc_entity_usage table.

The client wiki will be subscribed to be informed about changes to any entity present in the local wbc_entity_usage table.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::__construct ( ClientDomainDb $clientDb,
RepoDomainDb $repoDb,
string $subscriberWikiId,
int $batchSize = 1000 )
Parameters
ClientDomainDb$clientDbDB manager for DB connections to the local wiki.
RepoDomainDb$repoDbDB manager for DB connections to the repo.
string$subscriberWikiIdThe local wiki's global ID, to be used as the subscriber ID in the repo's subscription table.
int$batchSize
Exceptions
InvalidArgumentException

Member Function Documentation

◆ deleteSubscriptionRange()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::deleteSubscriptionRange ( string $minId,
string $maxId )
private

Deletes a range of subscriptions.

Parameters
string$minIdEntity id string indicating the first element in the deletion range
string$maxIdEntity id string indicating the last element in the deletion range

◆ getDeletionRange()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::getDeletionRange ( array & $continuation = null)
private

Returns a range of entity IDs to delete, based on this updater's batch size.

Parameters
array | null&$continuation
Returns
array|false list( $minId, $maxId, $count ), or false if there is nothing to delete
Note
Below, we query and iterate all rows we want to delete in the current batch. That is rather ugly, but appears to be the best solution, because:
  • Deletions must be paged to avoid lock retention.
  • DELETE does not support LIMIT, so we need to know a range (min/max) of IDs.
  • GROUP BY does not support LIMIT, so we cannot use aggregate functions to get the min/max IDs.

Thus, using SELECT ... LIMIT seems to be the only reliable way to get the min/max range needed for batched deletion.

◆ getEntityIdsFromRows()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::getEntityIdsFromRows ( IResultWrapper $res,
$entityIdField,
array & $continuation = null )
private

Extracts entity id strings from the rows in a query result, and updates $continuation to a position "after" the content of the given query result.

Parameters
IResultWrapper$resA result set with the field given by $entityIdField field set for each row. The result is expected to be sorted by entity id, in ascending order.
string$entityIdFieldThe name of the field that contains the entity id.
array | null&$continuationUpdated to an array containing the last EntityId in the result.
Returns
string[] A list of entity ids strings.

◆ getUpdateBatch()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::getUpdateBatch ( array & $continuation = null)
private
Parameters
array | null&$continuation
Returns
string[] A list of entity id strings.

◆ insertUpdateBatch()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::insertUpdateBatch ( array $entities)
private
Parameters
string[]$entitiesEntity-IDs to subscribe to
Returns
int The number of rows inserted.

◆ makeSubscriptionRows()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::makeSubscriptionRows ( array $entities)
private

Returns a list of rows for insertion, using DatabaseBase's multi-row insert mechanism.

Each row is represented as [ $entityId, $subscriber ].

Parameters
string[]$entitiesentity id strings
Returns
array[] rows

◆ processDeletionBatch()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::processDeletionBatch ( array & $continuation = null)
private
Parameters
array | null&$continuation
Returns
int The number of subscriptions deleted.

◆ processUpdateBatch()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::processUpdateBatch ( array & $continuation = null)
private
Parameters
array | null&$continuation
Returns
int The number of subscriptions inserted.

◆ purgeSubscriptions()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::purgeSubscriptions ( EntityId $startEntity = null)

Remove subscriptions for entities not present in in wbc_entity_usage.

Parameters
EntityId | null$startEntityThe entity to start with.

◆ setProgressReporter()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::setProgressReporter ( MessageReporter $progressReporter)

◆ updateSubscriptions()

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::updateSubscriptions ( EntityId $startEntity = null)

Insert subscriptions based on entries in wbc_entity_usage.

Parameters
EntityId | null$startEntityThe entity to start with.

Member Data Documentation

◆ $batchSize

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$batchSize
private

◆ $localConnectionManager

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$localConnectionManager
private

◆ $progressReporter

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$progressReporter
private

◆ $repoConnectionManager

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$repoConnectionManager
private

◆ $repoDb

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$repoDb
private

◆ $subscriberWikiId

Wikibase\Client\Store\Sql\BulkSubscriptionUpdater::$subscriberWikiId
private

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