Legoktm has uploaded a new change for review.

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

Change subject: Expose DispatchStats info in the API
......................................................................

Expose DispatchStats info in the API

Bug: 46642
Change-Id: Iaff8b6ef80f7b0681db7530f5e45acd7147c82c8
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
2 files changed, 52 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/92/132592/1

diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 3c78015..6082c32 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -1277,4 +1277,55 @@
                return new PropertyHandler( $validators );
        }
 
+       /**
+        * Helper for onAPIQuerySiteInfoStatisticsInfo
+        * @param object $row
+        * @return array
+        */
+       private static function formatDispatchRow( $row ) {
+               $data = array(
+                       'pending' => $row->chd_pending,
+                       'lag' => $row->chd_lag,
+               );
+               if ( isset( $row->chd_site ) ) {
+                       $data['site'] = $row->chd_site;
+               }
+               if ( isset( $row->chd_seen ) ) {
+                       $data['position'] = $row->chd_seen;
+               }
+               if ( isset( $row->chd_touched ) ) {
+                       $data['touched'] = $row->chd_touched;
+               }
+
+               return $data;
+       }
+
+       /**
+        * Adds DispatchStats info to the API
+        * @param array $data
+        * @return bool
+        */
+       public static function onAPIQuerySiteInfoStatisticsInfo( array &$data ) 
{
+               $stats = new DispatchStats();
+               $stats->load();
+               if ( $stats->hasStats() ) {
+                       $data['dispatch'] = array(
+                               'oldest' => array(
+                                       'id' => $stats->getMinChangeId(),
+                                       'timestamp' => 
$stats->getMinChangeTimestamp(),
+                               ),
+                               'newest' => array(
+                                       'id' => $stats->getMaxChangeId(),
+                                       'timestamp' => 
$stats->getMaxChangeTimestamp(),
+                               ),
+                               'freshest' => self::formatDispatchRow( 
$stats->getFreshest() ),
+                               'median' => self::formatDispatchRow( 
$stats->getMedian() ),
+                               'stalest' => self::formatDispatchRow( 
$stats->getStalest() ),
+                               'average' => self::formatDispatchRow( 
$stats->getAverage() ),
+                       );
+               }
+
+               return true;
+       }
+
 }
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index b83aeb9..10fd985 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -180,6 +180,7 @@
        $wgHooks['OutputPageBeforeHTML'][]                              = 
'Wikibase\RepoHooks::onOutputPageBeforeHtmlRegisterConfig';
        $wgHooks['MakeGlobalVariablesScript'][]                 = 
'Wikibase\RepoHooks::onMakeGlobalVariablesScript';
        $wgHooks['ContentHandlerForModelID'][]                  = 
'Wikibase\RepoHooks::onContentHandlerForModelID';
+       $wgHooks['APIQuerySiteInfoStatisticsInfo'][]    = 
'Wikibase\RepoHooks::onAPIQuerySiteInfoStatisticsInfo';
 
        // Resource Loader Modules:
        $wgResourceModules = array_merge( $wgResourceModules, include( __DIR__ 
. "/resources/Resources.php" ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaff8b6ef80f7b0681db7530f5e45acd7147c82c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to