Aaron Schulz has uploaded a new change for review.

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

Change subject: Updated numUsersWatchingPage() to use recentchanges
......................................................................

Updated numUsersWatchingPage() to use recentchanges

* Login no longer bumps user_touched, and that was hacky anyway

Change-Id: I0eed387592241bcc2c02b79868778d84b75fdb00
---
M backend/FRUserActivity.php
1 file changed, 15 insertions(+), 10 deletions(-)


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

diff --git a/backend/FRUserActivity.php b/backend/FRUserActivity.php
old mode 100644
new mode 100755
index 5034633..254e8b6
--- a/backend/FRUserActivity.php
+++ b/backend/FRUserActivity.php
@@ -12,31 +12,36 @@
         * @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_namespace' => $title->getNamespace(),
+                               'wl_title'     => $title->getDBkey(),
                                'wl_user = user_id',
-                               'user_touched > ' . $dbr->addQuotes( $cutoff ) 
// logged in or out
+                               'EXISTS(' . $dbr->selectSQLText(
+                                       'recentchanges',
+                                       '1',
+                                       'user_name = rc_user_text',
+                                       'rc_timestamp > ' . $dbr->timestamp( 
time() - 86400 * $wgActiveUserDays )
+                               ) . ')'
                        ),
                        __METHOD__
                );
-               if ( $count > 10 ) {
-                       # Save new value to cache (more aggresive for larger 
counts)
-                       $wgMemc->set( $key, $count, ( $count > 200 ) ? 30*60 : 
5*60 );
-               }
+
+               # Save new value to cache (more aggresive for larger counts)
+               $wgMemc->set( $key, $count, ( $count > 100 ) ? 30*60 : 5*60 );
 
                return $count;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0eed387592241bcc2c02b79868778d84b75fdb00
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