Kaynağa Gözat

Minor tweaks to metadata API

Jordi Boggiano 5 yıl önce
ebeveyn
işleme
d00863d1b0

+ 4 - 4
src/Packagist/WebBundle/Controller/PackageController.php

@@ -118,10 +118,10 @@ class PackageController extends Controller
 
         $since = $req->query->getInt('since');
         if (!$since || $since < 15850612240000) {
-            return new JsonResponse(['error' => 'Invalid or missing "since" query parameter, make sure you store the timestamp (as `microtime(true) * 10000`) at the initial point you started mirroring, then send that to begin receiving changes, e.g. '.$this->generateUrl('metadata_changes', ['since' => $now], UrlGeneratorInterface::ABSOLUTE_URL).' for example.'], 400);
+            return new JsonResponse(['error' => 'Invalid or missing "since" query parameter, make sure you store the timestamp at the initial point you started mirroring, then send that to begin receiving changes, e.g. '.$this->generateUrl('metadata_changes', ['since' => $now], UrlGeneratorInterface::ABSOLUTE_URL).' for example.', 'timestamp' => $now], 400);
         }
         if ($since < $oldestSyncPoint) {
-            return new JsonResponse(['actions' => ['type' => 'resync', 'time' => $now, 'package' => '*'], 'timestamp' => $now]);
+            return new JsonResponse(['actions' => ['type' => 'resync', 'time' => floor($now / 10000), 'package' => '*'], 'timestamp' => $now]);
         }
 
         // fetch changes from $since (inclusive) up to $now (non inclusive so -1)
@@ -130,14 +130,14 @@ class PackageController extends Controller
 
         $actions = [];
         foreach ($dumps as $package => $time) {
-            $actions[$package] = ['type' => 'update', 'package' => $package, 'time' => (int) $time];
+            $actions[$package] = ['type' => 'update', 'package' => $package, 'time' => floor($time / 10000)];
         }
         foreach ($deletes as $package => $time) {
             // if a package is dumped then deleted then dumped again because it gets re-added, we want to keep the update action
             // but if it is deleted and marked as dumped within 10 seconds of the deletion, it probably was a race condition between
             // dumped job and deletion, so let's replace it by a delete job anyway
             if (!isset($actions[$package]) || $actions[$package]['time'] < $time - (10 * 10000)) {
-                $actions[$package] = ['type' => 'delete', 'package' => $package, 'time' => (int) $time];
+                $actions[$package] = ['type' => 'delete', 'package' => $package, 'time' => floor($time / 10000)];
             }
         }
 

+ 6 - 1
src/Packagist/WebBundle/Package/SymlinkDumper.php

@@ -545,6 +545,11 @@ class SymlinkDumper
 
     private function cleanOldFiles($buildDir, $oldBuildDir, $safeFiles)
     {
+        $time = (time() - 86400) * 10000;
+        $this->redis->set('metadata-oldest', $time);
+        $this->redis->zremrangebyscore('metadata-dumps', 0, $time-1);
+        $this->redis->zremrangebyscore('metadata-deletes', 0, $time-1);
+
         $finder = Finder::create()->directories()->ignoreVCS(true)->in($buildDir);
         foreach ($finder as $vendorDir) {
             $vendorFiles = Finder::create()->files()->ignoreVCS(true)
@@ -864,7 +869,7 @@ class SymlinkDumper
         file_put_contents($path.'.tmp', $contents);
         rename($path.'.tmp', $path);
 
-        if (!preg_match('{/([^/]+/[^/]+)(~dev)?\.json}', $path, $match)) {
+        if (!preg_match('{/([^/]+/[^/]+?)(~dev)?\.json$}', $path, $match)) {
             throw new \LogicException('Could not match package name from '.$path);
         }
         $this->redis->zadd('metadata-dumps', $timestamp, $match[1]);