objectcache: Optimise SqlBagOStuff::incrWithInit with WRITE_BACKGROUND
Bug: T310662 Bug: T261744 Change-Id: I9549722ff6f0c4d62d1bcbe8de55f51758157ec4
This commit is contained in:
parent
7fa8cf0164
commit
79afc20506
1 changed files with 43 additions and 1 deletions
|
|
@ -269,8 +269,14 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
|
||||||
protected function doIncrWithInit( $key, $exptime, $step, $init, $flags ) {
|
protected function doIncrWithInit( $key, $exptime, $step, $init, $flags ) {
|
||||||
$mtime = $this->getCurrentTime();
|
$mtime = $this->getCurrentTime();
|
||||||
|
|
||||||
|
if ( $flags & self::WRITE_BACKGROUND ) {
|
||||||
|
$callback = [ $this, 'modifyTableSpecificBlobsForIncrInitAsync' ];
|
||||||
|
} else {
|
||||||
|
$callback = [ $this, 'modifyTableSpecificBlobsForIncrInit' ];
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->modifyBlobs(
|
$result = $this->modifyBlobs(
|
||||||
[ $this, 'modifyTableSpecificBlobsForIncrInit' ],
|
$callback,
|
||||||
$mtime,
|
$mtime,
|
||||||
[ $key => [ $step, $init, $exptime ] ],
|
[ $key => [ $step, $init, $exptime ] ],
|
||||||
$flags,
|
$flags,
|
||||||
|
|
@ -986,6 +992,42 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
|
||||||
$this->updateOpStats( self::METRIC_OP_INCR, array_keys( $argsByKey ) );
|
$this->updateOpStats( self::METRIC_OP_INCR, array_keys( $argsByKey ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as modifyTableSpecificBlobsForIncrInit() but does not return the
|
||||||
|
* new value.
|
||||||
|
*
|
||||||
|
* @param IDatabase $db
|
||||||
|
* @param string $ptable
|
||||||
|
* @param float $mtime
|
||||||
|
* @param array<string,array> $argsByKey
|
||||||
|
* @param array<string,mixed> &$resByKey
|
||||||
|
* @throws DBError
|
||||||
|
*/
|
||||||
|
private function modifyTableSpecificBlobsForIncrInitAsync(
|
||||||
|
IDatabase $db,
|
||||||
|
string $ptable,
|
||||||
|
float $mtime,
|
||||||
|
array $argsByKey,
|
||||||
|
array &$resByKey
|
||||||
|
) {
|
||||||
|
foreach ( $argsByKey as $key => list( $step, $init, $exptime ) ) {
|
||||||
|
$mt = $this->makeTimestampedModificationToken( $mtime, $db );
|
||||||
|
$expiry = $this->makeNewKeyExpiry( $exptime, (int)$mtime );
|
||||||
|
$db->upsert(
|
||||||
|
$ptable,
|
||||||
|
$this->buildUpsertRow( $db, $key, $init, $expiry, $mt ),
|
||||||
|
[ [ 'keyname' ] ],
|
||||||
|
$this->buildIncrUpsertSet( $db, $step, $init, $expiry, $mt, (int)$mtime ),
|
||||||
|
__METHOD__
|
||||||
|
);
|
||||||
|
if ( !$db->affectedRows() ) {
|
||||||
|
$this->logger->warning( __METHOD__ . ": failed to set new $key value" );
|
||||||
|
} else {
|
||||||
|
$resByKey[$key] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $exptime Relative or absolute expiration
|
* @param int $exptime Relative or absolute expiration
|
||||||
* @param int $nowTsUnix Current UNIX timestamp
|
* @param int $nowTsUnix Current UNIX timestamp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue