Parcourir la source

Start collecting monthly/daily totals at the same time as we track to deprecate part of the CompileStatsCommand

Plus optimizes storage of throttle keys
Jordi Boggiano il y a 7 ans
Parent
commit
7eef3e6caf

+ 6 - 4
src/Packagist/Redis/DownloadsIncr.php

@@ -12,7 +12,7 @@ class DownloadsIncr extends \Predis\Command\ScriptCommand
             throw new \LogicException('getKeysCount called before filterArguments');
         }
 
-        return count($this->args);
+        return count($this->args) - 1;
     }
 
     protected function filterArguments(array $arguments)
@@ -28,10 +28,10 @@ class DownloadsIncr extends \Predis\Command\ScriptCommand
 local doIncr = false;
 local successful = 0;
 for i, key in ipairs(KEYS) do
-    if i == 1 then
+    if i <= 3 then
         -- nothing
-    elseif ((i - 2) % 7) == 0 then
-        local requests = redis.call("INCR", key);
+    elseif ((i - 4) % 7) == 0 then
+        local requests = tonumber(redis.call("ZINCRBY", key, 1, ARGV[1]));
         if 1 == requests then
             redis.call("EXPIRE", key, 86400);
         end
@@ -48,6 +48,8 @@ end
 
 if successful > 0 then
     redis.call("INCRBY", KEYS[1], successful);
+    redis.call("INCRBY", KEYS[2], successful);
+    redis.call("INCRBY", KEYS[3], successful);
 end
 
 return redis.status_reply("OK");

+ 4 - 2
src/Packagist/WebBundle/Model/DownloadManager.php

@@ -121,14 +121,14 @@ class DownloadManager
             $this->redisCommandLoaded = true;
         }
 
-        $args = ['downloads'];
+        $args = ['downloads', 'downloads:'.$day, 'downloads:'.$month];
 
         foreach ($jobs as $job) {
             $package = $job['id'];
             $version = $job['vid'];
 
             // throttle key
-            $args[] = 'throttle:'.$package.':'.$job['ip'].':'.$day;
+            $args[] = 'throttle:'.$package.':'.$day;
             // stats keys
             $args[] = 'dl:'.$package;
             $args[] = 'dl:'.$package.':'.$month;
@@ -138,6 +138,8 @@ class DownloadManager
             $args[] = 'dl:'.$package.'-'.$version.':'.$day;
         }
 
+        $args[] = $job['ip'];
+
         $this->redis->downloadsIncr(...$args);
     }
 }