24use Psr\Log\LoggerInterface;
26use Wikimedia\Assert\Assert;
95 $this->loadBalancer = $dbLoadBalancer;
103 $this->cacheTTL = IExpiringStore::TTL_MONTH;
114 return $this->loadBalancer->getConnection( $index, [], $this->wikiId, $flags );
126 return $this->
cache->makeGlobalKey(
129 $this->loadBalancer->resolveDomainID( $this->wikiId )
138 if ( $this->normalizationCallback ===
null ) {
141 return call_user_func( $this->normalizationCallback, $name );
153 Assert::parameterType(
'string', $name,
'$name' );
157 $searchResult = array_search( $name,
$table,
true );
158 if ( $searchResult ===
false ) {
159 $id = $this->
store( $name );
160 if ( $id ===
null ) {
165 $connFlags = defined(
'MW_PHPUNIT_TEST' ) ? 0 : ILoadBalancer::CONN_TRX_AUTOCOMMIT;
168 $searchResult = array_search( $name,
$table,
true );
169 if ( $searchResult ===
false ) {
171 $m =
"No insert possible but master didn't give us a record for " .
172 "'{$name}' in '{$this->table}'";
173 $this->logger->error( $m );
176 } elseif ( isset(
$table[$id] ) ) {
178 "Expected unused ID from database insert for '$name' "
179 .
" into '{$this->table}', but ID $id is already associated with"
180 .
" the name '{$table[$id]}'! This may indicate database corruption!" );
192 $this->tableCache =
$table;
195 return $searchResult;
234 Assert::parameterType(
'string', $name,
'$name' );
238 $searchResult = array_search( $name,
$table,
true );
240 if ( $searchResult !==
false ) {
241 return $searchResult;
259 Assert::parameterType(
'integer', $id,
'$id' );
262 if ( array_key_exists( $id,
$table ) ) {
270 function ( $oldValue, &$ttl, &$setOpts ) use ( $id,
$fname ) {
272 if ( is_array( $oldValue ) && array_key_exists( $id, $oldValue ) ) {
274 $ttl = WANObjectCache::TTL_UNCACHEABLE;
283 $fname .
' falling back to master select from ' .
284 $this->
table .
' with id ' . $id
288 $cacheSetOpts = Database::getCacheSetOptions( $db );
290 if ( array_key_exists( $id,
$table ) ) {
295 $setOpts += $cacheSetOpts;
302 $this->tableCache =
$table;
304 if ( array_key_exists( $id,
$table ) ) {
326 if ( $this->tableCache !==
null ) {
333 function ( $oldValue, &$ttl, &$setOpts ) {
335 $setOpts += Database::getCacheSetOptions(
$dbr );
340 $this->tableCache =
$table;
352 if ( !$this->loadBalancer->hasOrMadeRecentMasterChanges() ) {
358 ->onTransactionPreCommitOrIdle( $purgeCallback, __METHOD__ );
372 'id' => $this->idField,
373 'name' => $this->nameField
377 [
'ORDER BY' =>
'id' ]
381 foreach ( $result as $row ) {
382 $assocArray[$row->id] = $row->name;
395 Assert::parameterType(
'string', $name,
'$name' );
396 Assert::parameter( $name !==
'',
'$name',
'should not be an empty string' );
408 if ( $dbw->affectedRows() === 0 ) {
410 'Tried to insert name into table ' . $this->
table .
', but value already existed.'
415 return $dbw->insertId();
423 $fields = [ $this->nameField =>
$name ];
424 if ( $this->insertCallback !==
null ) {
425 $fields = call_user_func( $this->insertCallback, $fields );
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
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