소스 검색

New splitting strategy for providers

Old format:
 - **latest**: until 10 hours before 1st day of current month.
 - **active**: 10-60 hours before 1st day of current month.
 - **stale**: 60-180 hours before 1st day of current month.
 - **archived**: more than 180 hours before 1st day of current month.

New format:
 - **latest**: until monday last week.
 - **YYYY-MM**: month block (03, 06, 09, 12), excluding what is in latest.
 - **YYYY**: year, excluding current
 - **archived**: Everything older than 2012

Rationale:

 * Split into smaller groups, resulting in faster download.
   This becomes a problem when Packagist is overloaded and/or
   the user has a slow connection - Composer times out.
 * Greatly reduces the changes to old providers.
   With the previous strategy, packages were switching constantly,
   causing cascading changes to all providers.

There is still the problem that the dumper relies on file modification
time, it would be best to switch to actual package modification
date.
Sébastien Lavoie 10 년 전
부모
커밋
f8eca74bec
1개의 변경된 파일25개의 추가작업 그리고 17개의 파일을 삭제
  1. 25 17
      src/Packagist/WebBundle/Package/SymlinkDumper.php

+ 25 - 17
src/Packagist/WebBundle/Package/SymlinkDumper.php

@@ -552,27 +552,35 @@ class SymlinkDumper
 
     private function getTargetListing($file)
     {
-        static $firstOfTheMonth;
-        if (!$firstOfTheMonth) {
-            $date = new \DateTime;
-            $date->setDate($date->format('Y'), $date->format('m'), 1);
-            $date->setTime(0, 0, 0);
-            $firstOfTheMonth = $date->format('U');
-        }
-
-        $mtime = filemtime($file);
+        static $limitLatest, $thisYear, $limitArchived;
 
-        if ($mtime < $firstOfTheMonth - 86400 * 180) {
-            return 'provider-archived.json';
-        }
-        if ($mtime < $firstOfTheMonth - 86400 * 60) {
-            return 'provider-stale.json';
+        if (!$limitLatest) {
+            $limitLatest   = new \DateTime('monday last week');
+            $thisYear      = new \DateTime(date('Y') . '-01-01');
+            $limitArchived = new \DateTime('2012-01-01');
         }
-        if ($mtime < $firstOfTheMonth - 86400 * 10) {
-            return 'provider-active.json';
+
+        $mtime = new \DateTime();
+        $mtime->setTimestamp(filemtime($file));
+
+        if ($mtime >= $limitLatest) {
+            $label = 'latest';
+        } elseif ($mtime >= $thisYear) {
+            // split current by chunks of 3 months, current month included
+            // past chunks will never be updated this year
+            $month = $mtime->format('n');
+            $month = ceil($month / 3) * 3;
+            $month = str_pad($month, 2, '0', STR_PAD_LEFT);
+
+            $label = $mtime->format('Y') . '-' . $month;
+        } elseif ($mtime >= $limitArchived) {
+            // split by years, limit at 2012 so we never update 'archived' again
+            $label = $mtime->format('Y');
+        } else {
+            $label = 'archived';
         }
 
-        return 'provider-latest.json';
+        return "provider-${label}.json";
     }
 
     private function writeFile($path, $contents, $mtime = null)