8 use InvalidArgumentException;
13 use Wikimedia\Timestamp\ConvertibleTimestamp;
24 private const FIRST_EDIT = 1;
25 private const LATEST_EDIT = 2;
28 private $actorMigration;
31 private $loadBalancer;
34 private $jobQueueGroup;
42 private $userEditCountCache = [];
54 $this->actorMigration = $actorMigration;
55 $this->loadBalancer = $loadBalancer;
56 $this->jobQueueGroup = $jobQueueGroup;
66 if ( !$user->isRegistered() ) {
70 $userId = $user->
getId();
71 $cacheKey =
'u' . $userId;
73 if ( isset( $this->userEditCountCache[ $cacheKey ] ) ) {
74 return $this->userEditCountCache[ $cacheKey ];
78 $count =
$dbr->selectField(
81 [
'user_id' => $userId ],
85 if ( $count ===
null ) {
90 $this->userEditCountCache[ $cacheKey ] = $count;
101 $actorWhere = $this->actorMigration->getWhere(
$dbr,
'rev_user', $user );
103 $count = (int)
$dbr->selectField(
104 [
'revision' ] + $actorWhere[
'tables'],
106 [ $actorWhere[
'conds'] ],
114 'userId' => $user->
getId(),
115 'editCount' => $count,
135 DeferredUpdates::POSTSEND
148 return $this->getUserEditTimestamp( $user, self::FIRST_EDIT, $flags );
160 return $this->getUserEditTimestamp( $user, self::LATEST_EDIT, $flags );
171 private function getUserEditTimestamp(
UserIdentity $user,
int $type,
int $flags = IDBAccessObject::READ_NORMAL ) {
177 $db = $this->loadBalancer->getConnectionRef( $index );
178 $actorWhere = $this->actorMigration->getWhere( $db,
'rev_user', $user );
180 $sortOrder = (
$type === self::FIRST_EDIT ) ?
'ASC' :
'DESC';
181 $time = $db->selectField(
182 [
'revision' ] + $actorWhere[
'tables'],
184 [ $actorWhere[
'conds'] ],
186 [
'ORDER BY' =>
"rev_timestamp $sortOrder" ],
194 return ConvertibleTimestamp::convert( TS_MW, $time );
206 $userId = $user->
getId();
207 $cacheKey =
'u' . $userId;
209 unset( $this->userEditCountCache[ $cacheKey ] );
220 throw new InvalidArgumentException( __METHOD__ .
' with an anonymous user' );
223 $userId = $user->
getId();
224 $cacheKey =
'u' . $userId;
226 $this->userEditCountCache[ $cacheKey ] = $editCount;
if(!defined('MW_SETUP_CALLBACK'))
Helper class for DAO classes.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Class for managing the deferral of updates within the scope of a PHP script invocation.
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
Class to handle enqueueing of background jobs.
Job that initializes an user's edit count.
Handles increment the edit count for a given set of users.
Interface for database access objects.