changeset 748:80e8dba83cdf

fix metrics that could crash after 5 min of inactivity
author Alain Mazy <am@orthanc.team>
date Fri, 20 Mar 2026 19:10:58 +0100
parents 6fd8630f295a
children 4f6da1267585
files Plugin/WeightedAverageMetrics.h
diffstat 1 files changed, 3 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Plugin/WeightedAverageMetrics.h	Wed Mar 18 21:24:29 2026 +0100
+++ b/Plugin/WeightedAverageMetrics.h	Fri Mar 20 19:10:58 2026 +0100
@@ -55,6 +55,7 @@
 
   void RemoveOldest()
   {
+    // note: the mutex must be locked
     boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
 
     if (values_.size() > 0)
@@ -88,15 +89,8 @@
     values_.push_back(Value(value, weight));
     totalWeightedValue_ += value * weight;
     totalWeight_ += weight;
-    boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
-
-    const Value& oldest = values_.front();
-    while ((now - oldest.time_).total_seconds() > duration_)
-    {
-      totalWeightedValue_ -= oldest.value_ * oldest.weight_;
-      totalWeight_ -= oldest.weight_;
-      values_.pop_front();
-    }
+    
+    RemoveOldest();
   }
 
   T GetAverage()