MediaWiki  master
MediaWiki\Storage\NameTableStore Class Reference

Public Member Functions

 __construct (ILoadBalancer $dbLoadBalancer, WANObjectCache $cache, LoggerInterface $logger, $table, $idField, $nameField, callable $normalizationCallback=null, $dbDomain=false, callable $insertCallback=null)
 acquireId (string $name)
 Acquire the id of the given name. More...
 getId (string $name)
 Get the id of the given name. More...
 getMap ()
 Get the whole table, in no particular order as a map of ids to names. More...
 getName (int $id)
 Get the name of the given id. More...
 reloadMap ( $connFlags=0)
 Reloads the name table from the primary database, and purges the WAN cache entry. More...

Detailed Description


Definition at line 37 of file NameTableStore.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Storage\NameTableStore::__construct ( ILoadBalancer  $dbLoadBalancer,
WANObjectCache  $cache,
LoggerInterface  $logger,
callable  $normalizationCallback = null,
  $dbDomain = false,
callable  $insertCallback = null 
ILoadBalancer$dbLoadBalancerA load balancer for acquiring database connections
WANObjectCache$cacheA cache manager for caching data. This can be the local wiki's default instance even if $dbDomain refers to a different wiki, since makeGlobalKey() is used to constructed a key that allows cached names from the same database to be re-used between wikis. For example, enwiki and frwiki will use the same cache keys for names from the wikidatawiki database, regardless of the cache's default key space.
callable | null$normalizationCallbackNormalization to be applied to names before being saved or queried. This should be a callback that accepts and returns a single string.
bool | string$dbDomainDatabase domain ID. Use false for the local database domain.
callable | null$insertCallbackCallback to change insert fields accordingly. This parameter was introduced in 1.32

Definition at line 86 of file NameTableStore.php.

References $cache.

Member Function Documentation

◆ acquireId()

MediaWiki\Storage\NameTableStore::acquireId ( string  $name)

Acquire the id of the given name.

This creates a row in the table if it doesn't already exist.

If called within an atomic section, there is a chance for the acquired ID to be lost on rollback. A best effort is made to re-insert the mapping in this case, and consistency of the cache with the database table is ensured by re-loading the map after a failed atomic section. However, there is no guarantee that an ID returned by this method is valid outside the transaction in which it was produced. This means that calling code should not retain the return value beyond the scope of a transaction, but rather call acquireId() again after the transaction is complete. In some rare cases, this may produce an ID different from the first call.

Definition at line 162 of file NameTableStore.php.

References Wikimedia\Rdbms\ILoadBalancer\CONN_TRX_AUTOCOMMIT, DB_PRIMARY, and MediaWiki\Storage\NameTableStore\reloadMap().

◆ getId()

MediaWiki\Storage\NameTableStore::getId ( string  $name)

Get the id of the given name.

If the name doesn't exist this will throw. This should be used in cases where we believe the name already exists or want to check for existence.

NameTableAccessExceptionThe name does not exist
int Id

Definition at line 251 of file NameTableStore.php.

References MediaWiki\Storage\NameTableAccessException\newFromDetails().

◆ getMap()

MediaWiki\Storage\NameTableStore::getMap ( )

Get the whole table, in no particular order as a map of ids to names.

This method could be subject to DB or cache lag.

string[] keys are the name ids, values are the names themselves Example: [ 1 => 'foo', 3 => 'bar' ]

Definition at line 333 of file NameTableStore.php.

◆ getName()

MediaWiki\Storage\NameTableStore::getName ( int  $id)

Get the name of the given id.

If the id doesn't exist this will throw. This should be used in cases where we believe the id already exists.

Note: Calls to this method will result in a primary DB select for non existing IDs.

NameTableAccessExceptionThe id does not exist
string name

Definition at line 275 of file NameTableStore.php.

References $source, DB_PRIMARY, DB_REPLICA, Wikimedia\Rdbms\Database\getCacheSetOptions(), and MediaWiki\Storage\NameTableAccessException\newFromDetails().

◆ reloadMap()

MediaWiki\Storage\NameTableStore::reloadMap (   $connFlags = 0)

Reloads the name table from the primary database, and purges the WAN cache entry.

This should only be called in situations where the local cache has been detected to be out of sync with the database. There should be no reason to call this method from outside the NameTableStore during normal operation. This method may however be useful in unit tests.
int$connFlagsILoadBalancer::CONN_XXX flags. Optional.
string[] The freshly reloaded name map

Definition at line 225 of file NameTableStore.php.

References DB_PRIMARY.

Referenced by MediaWiki\Storage\NameTableStore\acquireId().

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