MediaWiki master
TableStatsProvider.php
Go to the documentation of this file.
1<?php
2
4
6
15 private ?int $minId;
16 private ?int $maxId;
17 private bool $loaded = false;
18
19 public function __construct(
20 private IConnectionProvider $connectionProvider,
21 private string $tableName,
22 private string $idField,
23 ) {
24 }
25
32 public function getIdDelta() {
33 $this->loadStats();
34 return $this->maxId === null ? 0 : $this->maxId - $this->minId;
35 }
36
42 public function getMinId() {
43 $this->loadStats();
44 return $this->minId;
45 }
46
52 public function getMaxId() {
53 $this->loadStats();
54 return $this->maxId;
55 }
56
57 private function loadStats() {
58 if ( $this->loaded ) {
59 return;
60 }
61 $this->loaded = true;
62
63 $info = $this->connectionProvider
64 ->getReplicaDatabase()
65 ->newSelectQueryBuilder()
66 ->select( [
67 'min_id' => "MIN({$this->idField})",
68 'max_id' => "MAX({$this->idField})",
69 ] )
70 ->from( $this->tableName )
71 ->caller( __METHOD__ )
72 ->fetchRow();
73 if ( $info ) {
74 $this->minId = (int)$info->min_id;
75 $this->maxId = (int)$info->max_id;
76 }
77 }
78}
Cache and provide min/max ID and "size" (ID delta) of a table.
__construct(private IConnectionProvider $connectionProvider, private string $tableName, private string $idField,)
getIdDelta()
Estimate the number of rows in the table, using the difference of maximum and minimum primary keys.
Provide primary and replica IDatabase connections.