API: Avoid duplicate logs to api-feature-usage
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 5 Mar 2019 22:43:16 +0000 (17:43 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 5 Mar 2019 22:56:55 +0000 (17:56 -0500)
It can wind up logging deprecations twice if extractRequestParams() is
called with different values for 'parseLimit', for example.

Change-Id: I921777089fb8cfb4339af6fd08ee3475ed31b7f6

includes/api/ApiBase.php

index 2ec4570..9b3d116 100644 (file)
@@ -2225,6 +2225,15 @@ abstract class ApiBase extends ContextSource {
         * @param string $feature Feature being used.
         */
        public function logFeatureUsage( $feature ) {
+               static $loggedFeatures = [];
+
+               // Only log each feature once per request. We can get multiple calls from calls to
+               // extractRequestParams() with different values for 'parseLimit', for example.
+               if ( isset( $loggedFeatures[$feature] ) ) {
+                       return;
+               }
+               $loggedFeatures[$feature] = true;
+
                $request = $this->getRequest();
                $ctx = [
                        'feature' => $feature,