Debian Codegraph @

includes/user/TempUser/LocalSerialProvider.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\User\TempUser;
4
5 use Wikimedia\Rdbms\ILoadBalancer;
6
7 /**
8 * A serial provider which allocates IDs from the local database, or from a
9 * shared database if $wgSharedDB is used. It is "local" in the sense that it
10 * uses the same DB connection as the local wiki.
11 *
12 * @since 1.39
13 */
14 class LocalSerialProvider extends DBSerialProvider {
15 private ILoadBalancer $lb;
16
17 /**
18 * @param array $config
19 * - numShards (int, default 1): A small integer. This can be set to a
20 * value greater than 1 to avoid acquiring a global lock when
21 * allocating IDs, at the expense of making the IDs be non-monotonic.
22 * @param ILoadBalancer $lb
23 */
24 public function __construct( $config, ILoadBalancer $lb ) {
25 parent::__construct( $config );
26 $this->lb = $lb;
27 }
28
29 protected function getDB() {
30 return $this->lb->getConnection(
31 DB_PRIMARY,
32 [],
33 false,
34 // So that startAtomic() will start a commit, reducing lock time.
35 // Without this flag, the transaction will be open until the start
36 // of request shutdown. This could be omitted to reduce the
37 // connection overhead, with numShards tuned upwards to compensate.
38 ILoadBalancer::CONN_TRX_AUTOCOMMIT
39 );
40 }
41
42 protected function getTableName() {
43 return 'user_autocreate_serial';
44 }
45 }