27 if ( $this->numShards ) {
28 $shard = mt_rand( 0, $this->numShards - 1 );
33 $dbw = $this->
getDB();
35 $dbw->startAtomic( __METHOD__ );
36 $dbw->newInsertQueryBuilder()
37 ->insertInto( $table )
39 'uas_shard' => $shard,
43 ->onDuplicateKeyUpdate()
44 ->uniqueIndexFields( [
'uas_shard',
'uas_year' ] )
45 ->set( [
'uas_value=uas_value+1' ] )
46 ->caller( __METHOD__ )->execute();
47 $value = $dbw->newSelectQueryBuilder()
48 ->select(
'uas_value' )
50 ->where( [
'uas_shard' => $shard ] )
51 ->andWhere( [
'uas_year' => $year ] )
52 ->caller( __METHOD__ )
54 $dbw->endAtomic( __METHOD__ );
55 return $value * $this->numShards + $shard;