8use InvalidArgumentException;
13use 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' . (string)$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,
133 DeferredUpdates::addUpdate(
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 ) {
175 list( $index ) = DBAccessObjectUtils::getDBOptions( $flags );
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' . (string)$userId;
209 unset( $this->userEditCountCache[ $cacheKey ] );
220 throw new InvalidArgumentException( __METHOD__ .
' with an anonymous user' );
223 $userId = $user->
getId();
224 $cacheKey =
'u' . (string)$userId;
226 $this->userEditCountCache[ $cacheKey ] = $editCount;
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Helper class for DAO classes.
Class for managing the deferral of updates within the scope of a PHP script invocation.
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.