From f1381932df78afcdc3ccfb2f356ec93d81f7ad24 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Tue, 14 Apr 2015 11:51:26 -0700 Subject: [PATCH] Don't bother buffering a counter update with a delta of zero. Counter updates with a delta of zero don't do anything, so there's no point in sending them over the wire. Change-Id: Iae82ee9c9a8544c94abfcbdf944bd713687dce9d --- includes/libs/BufferingStatsdDataFactory.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/libs/BufferingStatsdDataFactory.php b/includes/libs/BufferingStatsdDataFactory.php index ea5b09dc7e..457237a2c8 100644 --- a/includes/libs/BufferingStatsdDataFactory.php +++ b/includes/libs/BufferingStatsdDataFactory.php @@ -20,8 +20,10 @@ * @file */ +use Liuggio\StatsdClient\Entity\StatsdDataInterface; use Liuggio\StatsdClient\Factory\StatsdDataFactory; + /** * A factory for application metric data. * @@ -38,8 +40,8 @@ class BufferingStatsdDataFactory extends StatsdDataFactory { $this->prefix = $prefix; } - public function produceStatsdData( $key, $value = 1, $metric = self::STATSD_METRIC_COUNT ) { - $this->buffer[] = $entity = $this->produceStatsdDataEntity(); + public function produceStatsdData( $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT ) { + $entity = $this->produceStatsdDataEntity(); if ( $key !== null ) { $prefixedKey = ltrim( $this->prefix . '.' . $key, '.' ); $entity->setKey( $prefixedKey ); @@ -50,6 +52,10 @@ class BufferingStatsdDataFactory extends StatsdDataFactory { if ( $metric !== null ) { $entity->setMetric( $metric ); } + // Don't bother buffering a counter update with a delta of zero. + if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) { + $this->buffer[] = $entity; + } return $entity; } -- 2.20.1