Browse Source

Avoid unnecessary work in the dumper

Jordi Boggiano 7 years ago
parent
commit
8bbbb737d5

+ 9 - 10
src/Packagist/WebBundle/Command/DumpPackagesCommand.php

@@ -53,6 +53,15 @@ class DumpPackagesCommand extends ContainerAwareCommand
             return;
         }
 
+        // another dumper is still active
+        $lock = new LockHandler('packagist_package_dumper');
+        if (!$lock->lock()) {
+            if ($verbose) {
+                $output->writeln('Aborting, another dumper is still active');
+            }
+            return;
+        }
+
         $doctrine = $this->getContainer()->get('doctrine');
 
         if ($force) {
@@ -72,19 +81,9 @@ class DumpPackagesCommand extends ContainerAwareCommand
             return 0;
         }
 
-        $lock = new LockHandler('packagist_package_dumper');
-
         ini_set('memory_limit', -1);
         gc_enable();
 
-        // another dumper is still active
-        if (!$lock->lock()) {
-            if ($verbose) {
-                $output->writeln('Aborting, another dumper is still active');
-            }
-            return;
-        }
-
         try {
              $result = $this->getContainer()->get('packagist.package_dumper')->dump($ids, $force, $verbose);
         } finally {

+ 1 - 1
src/Packagist/WebBundle/Entity/PackageRepository.php

@@ -152,7 +152,7 @@ class PackageRepository extends EntityRepository
     {
         $conn = $this->getEntityManager()->getConnection();
 
-        return $conn->fetchAll('SELECT p.id FROM package p WHERE p.dumpedAt IS NULL OR p.dumpedAt <= p.crawledAt  ORDER BY p.id ASC');
+        return $conn->fetchAll('SELECT p.id FROM package p WHERE p.dumpedAt IS NULL OR p.dumpedAt <= p.crawledAt AND p.crawledAt < NOW() ORDER BY p.id ASC');
     }
 
     public function getPartialPackageByNameWithVersions($name)