Selaa lähdekoodia

correction de la requete sql des compteurs

dpacaud 12 vuotta sitten
vanhempi
commit
3026f93ce0
2 muutettua tiedostoa jossa 3 lisäystä ja 15 poistoa
  1. 2 2
      engines/countersEngine.js
  2. 1 13
      tables/counters_statistics.sql

+ 2 - 2
engines/countersEngine.js

@@ -27,8 +27,8 @@ MySQLBackendCountersEngine.prototype.buildQuerries = function(userCounters, time
          *    - userCounterName: Counter name
          *    - counterValue: Counter value
          */
-        //querries.push("insert into `counters_statistics` (`timestamp`,`name`,`value`) values(" + time_stamp + ",'" + userCounterName +"'," + counterValue + ") on duplicate key update value = value + " + counterValue + ", timestamp = " + time_stamp);
-        querries.push("insert into `counters_statistics` values ("+time_stamp+", '"+userCounterName+"', counters_get_max(name) + "+counterValue+");");
+        querries.push("insert into `counters_statistics` select "+time_stamp+", '"+userCounterName+"' , if(max(value),max(value),0) + "+counterValue+"  from `counters_statistics`  where if(name = '"+userCounterName+"', 1,0) = 1 ;");
+
       }
     }
 

+ 1 - 13
tables/counters_statistics.sql

@@ -5,17 +5,4 @@ CREATE  TABLE `statsd_db`.`counters_statistics` (
     `timestamp` BIGINT NOT NULL ,
     `name` VARCHAR(255) NOT NULL ,
     `value` INT(11) NOT NULL ,
-PRIMARY KEY (`name`, `timestamp`) )$$
-
-CREATE FUNCTION `counters_get_max`(_name VARCHAR(255)) RETURNS INT(11)
-READS SQL DATA
-BEGIN 
-      DECLARE r INT;
-      SELECT  MAX(`value`)
-      INTO    r
-      FROM    `statsd_db`.`counters_statistics`
-      WHERE   name = _name;
-      
-      RETURN IF(r IS NULL, 0, r);
-END$$
+PRIMARY KEY (`timestamp`) )$$