X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryInfo.php;h=2d382dd54eb3846c4ad08608535eb08f8e67a066;hb=84e882968704febff2b4f0b3861e4e9845c5d4a4;hp=3aa0122d7d781cc27059ed0ed83c9adf49c95537;hpb=306b89853ee1b783dceadf62b8048ae616a04da2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 3aa0122d7d..2d382dd54e 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -453,13 +453,15 @@ class ApiQueryInfo extends ApiQueryBase { } if ( $this->fld_watchers ) { - if ( $this->watchers[$ns][$dbkey] !== 0 || $this->showZeroWatchers ) { + if ( $this->watchers !== null && $this->watchers[$ns][$dbkey] !== 0 ) { $pageInfo['watchers'] = $this->watchers[$ns][$dbkey]; + } elseif ( $this->showZeroWatchers ) { + $pageInfo['watchers'] = 0; } } if ( $this->fld_visitingwatchers ) { - if ( isset( $this->visitingwatchers[$ns][$dbkey] ) ) { + if ( $this->visitingwatchers !== null && $this->visitingwatchers[$ns][$dbkey] !== 0 ) { $pageInfo['visitingwatchers'] = $this->visitingwatchers[$ns][$dbkey]; } elseif ( $this->showZeroWatchers ) { $pageInfo['visitingwatchers'] = 0; @@ -829,14 +831,7 @@ class ApiQueryInfo extends ApiQueryBase { $this->showZeroWatchers = $canUnwatchedpages; - // Assemble a WHERE condition to find: - // * if the page exists, number of users watching who have - // visited the page recently - // * if the page doesn't exist, number of users that have - // the page on their watchlist - $whereStrings = []; - - // For pages that exist + $titlesWithThresholds = []; if ( $this->titles ) { $lb = new LinkBatch( $this->titles ); @@ -851,55 +846,38 @@ class ApiQueryInfo extends ApiQueryBase { $this->addOption( 'GROUP BY', [ 'page_namespace', 'page_title' ] ); $timestampRes = $this->select( __METHOD__ ); - // Assemble SQL WHERE condition to find number of page watchers who also - // visited a "recent" edit (last visited about 26 weeks before latest edit) $age = $config->get( 'WatchersMaxAge' ); $timestamps = []; foreach ( $timestampRes as $row ) { $revTimestamp = wfTimestamp( TS_UNIX, (int)$row->rev_timestamp ); - $threshold = $db->timestamp( $revTimestamp - $age ); - $timestamps[$row->page_namespace][$row->page_title] = $threshold; - } - - foreach ( $timestamps as $ns_key => $namespace ) { - $pageStrings = []; - foreach ( $namespace as $pg_key => $threshold ) { - $pageStrings[] = "wl_title = '$pg_key' AND" . - ' (wl_notificationtimestamp >= ' . - $db->addQuotes( $threshold ) . - ' OR wl_notificationtimestamp IS NULL)'; - } - $whereStrings[] = "wl_namespace = '$ns_key' AND (" . - $db->makeList( $pageStrings, LIST_OR ) . ')'; + $timestamps[$row->page_namespace][$row->page_title] = $revTimestamp - $age; } + $titlesWithThresholds = array_map( + function( LinkTarget $target ) use ( $timestamps ) { + return [ + $target, $timestamps[$target->getNamespace()][$target->getDBkey()] + ]; + }, + $this->titles + ); } - // For nonexistant pages if ( $this->missing ) { - $lb = new LinkBatch( $this->missing ); - $whereStrings[] = $lb->constructSet( 'wl', $db ); - } - - // Make the actual string and do the query - $whereString = $db->makeList( $whereStrings, LIST_OR ); - - $this->resetQueryParams(); - $this->addTables( [ 'watchlist' ] ); - $this->addFields( [ - 'wl_namespace', - 'wl_title', - 'count' => 'COUNT(*)' - ] ); - $this->addWhere( [ $whereString ] ); - $this->addOption( 'GROUP BY', [ 'wl_namespace', 'wl_title' ] ); - if ( !$canUnwatchedpages ) { - $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" ); - } - - $res = $this->select( __METHOD__ ); - foreach ( $res as $row ) { - $this->visitingwatchers[$row->wl_namespace][$row->wl_title] = (int)$row->count; - } + $titlesWithThresholds = array_merge( + $titlesWithThresholds, + array_map( + function( LinkTarget $target ) { + return [ $target, null ]; + }, + $this->missing + ) + ); + } + + $this->visitingwatchers = WatchedItemStore::getDefaultInstance()->countVisitingWatchersMultiple( + $titlesWithThresholds, + !$canUnwatchedpages ? $unwatchedPageThreshold : null + ); } public function getCacheMode( $params ) {