From 3a94a6d27fcfd5f0dfc4a05393dd9fc97b8c7bf8 Mon Sep 17 00:00:00 2001 From: Alexander Markevich Date: Tue, 7 Mar 2017 16:21:38 +0200 Subject: [PATCH] Increase LastUpdate timestamp precission --- cbp/modules/Quotas.pm | 10 +++++----- database/quotas.tsql | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cbp/modules/Quotas.pm b/cbp/modules/Quotas.pm index 0d4794c..ca2feac 100644 --- a/cbp/modules/Quotas.pm +++ b/cbp/modules/Quotas.pm @@ -21,7 +21,7 @@ package cbp::modules::Quotas; use strict; use warnings; - +use Time::HiRes; use cbp::logging; use awitpt::db::dblayer; @@ -94,7 +94,7 @@ sub check { # Our verdict and data my ($verdict,$verdict_data); - my $now = time(); + my $now = Time::HiRes::time; # @@ -178,7 +178,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}} # Calculate the % of the period we have, and multiply it with the counter ... this should give us a reasonably # accurate counting } else { - $currentCounter = ( 1 - ($elapsedTime / $quota->{'Period'}) ) * $qtrack->{'Counter'}; + $currentCounter = ( 1.0 - ($elapsedTime / $quota->{'Period'}) ) * $qtrack->{'Counter'}; } # Work out the difference to the DB value, we ONLY DO THIS ONCE!!! so if its defined, leave it alone! @@ -196,7 +196,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}} $hasExceeded = "Policy rejection; Message count quota exceeded"; } # Bump up limit - $newCounters{$qtrack->{'QuotasLimitsID'}}++; + $newCounters{$qtrack->{'QuotasLimitsID'}} += 1.0; # Check for cumulative size violation } elsif ($limitType eq "messagecumulativesize") { @@ -220,7 +220,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}} # Check if this is a message counter if (lc($limit->{'Type'}) eq "messagecount") { # Bump up limit - $newCounters{$qtrack->{'QuotasLimitsID'}}++; + $newCounters{$qtrack->{'QuotasLimitsID'}} += 1.0; } } diff --git a/database/quotas.tsql b/database/quotas.tsql index 076fedd..baa97e1 100644 --- a/database/quotas.tsql +++ b/database/quotas.tsql @@ -79,7 +79,7 @@ CREATE TABLE @PREFIX@quotas_tracking ( TrackKey VARCHAR(@TRACK_KEY_LEN@), /* Last time this record was update */ - LastUpdate @BIG_INTEGER_UNSIGNED@, /* NULL means not updated yet */ + LastUpdate NUMERIC(10,4), /* NULL means not updated yet */ Counter NUMERIC(10,4), -- GitLab