24use Psr\Log\LoggerInterface;
26use Wikimedia\Assert\Assert;
85 $this->loadBalancer = $dbLoadBalancer;
93 $this->cacheTTL = IExpiringStore::TTL_MONTH;
103 return $this->loadBalancer->getConnection( $index, [], $this->wikiId, $flags );
107 return $this->
cache->makeKey(
'NameTableSqlStore', $this->
table, $this->wikiId );
115 if ( $this->normalizationCallback ===
null ) {
118 return call_user_func( $this->normalizationCallback, $name );
130 Assert::parameterType(
'string', $name,
'$name' );
134 $searchResult = array_search( $name,
$table,
true );
135 if ( $searchResult ===
false ) {
136 $id = $this->
store( $name );
137 if ( $id ===
null ) {
143 $searchResult = array_search( $name,
$table,
true );
144 if ( $searchResult ===
false ) {
146 $m =
"No insert possible but master didn't give us a record for " .
147 "'{$name}' in '{$this->table}'";
148 $this->logger->error( $m );
166 $this->tableCache =
$table;
169 return $searchResult;
183 Assert::parameterType(
'string', $name,
'$name' );
187 $searchResult = array_search( $name,
$table,
true );
189 if ( $searchResult !==
false ) {
190 return $searchResult;
208 Assert::parameterType(
'integer', $id,
'$id' );
211 if ( array_key_exists( $id,
$table ) ) {
218 function ( $oldValue, &$ttl, &$setOpts ) use ( $id ) {
220 if ( is_array( $oldValue ) && array_key_exists( $id, $oldValue ) ) {
222 $ttl = WANObjectCache::TTL_UNCACHEABLE;
231 __METHOD__ .
'falling back to master select from ' .
232 $this->
table .
' with id ' . $id
236 $cacheSetOpts = Database::getCacheSetOptions( $db );
238 if ( array_key_exists( $id,
$table ) ) {
243 $setOpts += $cacheSetOpts;
250 $this->tableCache =
$table;
252 if ( array_key_exists( $id,
$table ) ) {
274 if ( $this->tableCache !==
null ) {
281 function ( $oldValue, &$ttl, &$setOpts ) {
283 $setOpts += Database::getCacheSetOptions(
$dbr );
288 $this->tableCache =
$table;
300 if ( !$this->loadBalancer->hasOrMadeRecentMasterChanges() ) {
306 ->onTransactionPreCommitOrIdle( $purgeCallback, __METHOD__ );
320 'id' => $this->idField,
321 'name' => $this->nameField
325 [
'ORDER BY' =>
'id' ]
329 foreach ( $result as $row ) {
330 $assocArray[$row->id] = $row->name;
343 Assert::parameterType(
'string', $name,
'$name' );
344 Assert::parameter( $name !==
'',
'$name',
'should not be an empty string' );
351 [ $this->nameField => $name ],
356 if ( $dbw->affectedRows() === 0 ) {
358 'Tried to insert name into table ' . $this->
table .
', but value already existed.'
363 return $dbw->insertId();
Multi-datacenter aware caching interface.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
Allows to change the fields on the form that will be generated $name
Generic base class for storage interfaces.
you have access to all of the normal MediaWiki so you can get a DB use the cache
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store