Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/212713

Change subject: [WIP] Updated numUsersWatchingPage to handle how User::touch() 
works
......................................................................

[WIP] Updated numUsersWatchingPage to handle how User::touch() works

* That method no longer updates the DB, so this needs to check cache

Change-Id: I4669911c8c69a2e1a17854d45dcfd4d63d128ae3
---
M backend/FRUserActivity.php
M frontend/specialpages/reports/PendingChanges_body.php
2 files changed, 35 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs 
refs/changes/13/212713/1

diff --git a/backend/FRUserActivity.php b/backend/FRUserActivity.php
old mode 100644
new mode 100755
index 5034633..474baf2
--- a/backend/FRUserActivity.php
+++ b/backend/FRUserActivity.php
@@ -12,31 +12,47 @@
         * @return int
         */
        public static function numUsersWatchingPage( Title $title ) {
-               global $wgMemc, $wgCookieExpiration;
+               global $wgMemc, $wgActiveUserDays;
+
                # Check the cache...
-               $key = wfMemcKey( 'flaggedrevs', 'usersWatching', 
$title->getArticleID() );
+               $key = wfMemcKey( 'flaggedrevs', 'users-watching', 
$title->getArticleID() );
                $val = $wgMemc->get( $key );
                if ( is_int( $val ) ) {
                        return $val; // cache hit
                }
-               # Get number of active editors watching this page...
-               $dbr = wfGetDB( DB_SLAVE );
-               $cutoff = $dbr->timestamp( wfTimestamp( TS_UNIX ) - 2 * 
$wgCookieExpiration );
-               $count = (int)$dbr->selectField(
-                       array( 'watchlist', 'user' ),
-                       'COUNT(*)',
-                       array(
-                               'wl_namespace'    => $title->getNamespace(),
-                               'wl_title'        => $title->getDBkey(),
-                               'wl_user = user_id',
-                               'user_touched > ' . $dbr->addQuotes( $cutoff ) 
// logged in or out
-                       ),
-                       __METHOD__
+
+               # Get the last-login timestamp (includes some other updates) 
for users
+               # watching this page. Avoids User object overhead by just 
checking keys.
+               # @TODO: avoid having to know the name of User keys
+               $timestamps = 
ObjectCache::getMainWANInstance()->getCheckKeyTimeMulti(
+                       array_map(
+                               function ( $userId ) {
+                                       return wfMemcKey( 'user-quicktouched', 
'id', $userId );
+                               },
+                               wfGetDB( DB_SLAVE )->selectFieldValues(
+                                       array( 'watchlist' ),
+                                       'wl_user',
+                                       array(
+                                               'wl_namespace' => 
$title->getNamespace(),
+                                               'wl_title'     => 
$title->getDBkey()
+                                       ),
+                                       __METHOD__,
+                                       array( 'LIMIT' => 100 ) // sanity
+                               )
+                       )
                );
-               if ( $count > 10 ) {
-                       # Save new value to cache (more aggresive for larger 
counts)
-                       $wgMemc->set( $key, $count, ( $count > 200 ) ? 30*60 : 
5*60 );
-               }
+
+               $cutoffUnix = time() - 86400 * $wgActiveUserDays;
+               # Get the number of those that are recent enough
+               $count = count( array_filter(
+                       $timestamps,
+                       function ( $timestamp ) use ( $cutoffUnix ) {
+                               return $timestamp > $cutoffUnix;
+                       }
+               ) );
+
+               # Save new value to cache (more aggresive for larger counts)
+               $wgMemc->set( $key, $count, ( $count > 100 ) ? 30*60 : 5*60 );
 
                return $count;
        }
diff --git a/frontend/specialpages/reports/PendingChanges_body.php 
b/frontend/specialpages/reports/PendingChanges_body.php
old mode 100644
new mode 100755

-- 
To view, visit https://gerrit.wikimedia.org/r/212713
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4669911c8c69a2e1a17854d45dcfd4d63d128ae3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to