فهرست منبع

Add autoUpdated field to avoid crawling every hour those packages that have the github hook

Jordi Boggiano 13 سال پیش
والد
کامیت
ca64920903
2فایلهای تغییر یافته به همراه32 افزوده شده و 2 حذف شده
  1. 25 0
      src/Packagist/WebBundle/Entity/Package.php
  2. 7 2
      src/Packagist/WebBundle/Entity/PackageRepository.php

+ 25 - 0
src/Packagist/WebBundle/Entity/Package.php

@@ -94,6 +94,11 @@ class Package
      */
     private $indexedAt;
 
+    /**
+     * @ORM\Column(type="boolean")
+     */
+    private $autoUpdated;
+
     private $entityRepository;
     private $repositoryClass;
 
@@ -416,4 +421,24 @@ class Package
     {
         return $this->type;
     }
+
+    /**
+     * Set autoUpdated
+     *
+     * @param Boolean $autoUpdated
+     */
+    public function setAutoUpdated($autoUpdated)
+    {
+        $this->autoUpdated = $autoUpdated;
+    }
+
+    /**
+     * Get autoUpdated
+     *
+     * @return Boolean
+     */
+    public function getAutoUpdated()
+    {
+        return $this->autoUpdated;
+    }
 }

+ 7 - 2
src/Packagist/WebBundle/Entity/PackageRepository.php

@@ -70,8 +70,12 @@ class PackageRepository extends EntityRepository
         $qb->select('p, v')
             ->from('Packagist\WebBundle\Entity\Package', 'p')
             ->leftJoin('p.versions', 'v')
-            ->where('p.crawledAt IS NULL OR p.crawledAt < ?0')
-            ->setParameters(array(new \DateTime('-1hour')));
+            ->where('p.crawledAt IS NULL')
+            ->orWhere('(p.autoUpdated = false AND p.crawledAt < :crawled)')
+            ->orWhere('(p.crawledAt < :autocrawled)')
+            ->setParameter('crawled', new \DateTime('-1hour')) // crawl packages by hand once an hour
+            ->setParameter('autocrawled', new \DateTime('-1week')); // crawl auto-updated packages just in case once a week
+
         return $qb->getQuery()->getResult();
     }
 
@@ -83,6 +87,7 @@ class PackageRepository extends EntityRepository
             ->leftJoin('p.versions', 'v')
             ->leftJoin('v.tags', 't')
             ->where('p.indexedAt IS NULL OR p.indexedAt < p.crawledAt');
+
         return $qb->getQuery()->getResult();
     }