浏览代码

Update migration and service

Daniel Supernault 2 年之前
父节点
当前提交
b64af89d40
共有 2 个文件被更改,包括 19 次插入2 次删除
  1. 18 2
      app/Services/ImportService.php
  2. 1 0
      database/migrations/2023_06_10_031634_create_import_posts_table.php

+ 18 - 2
app/Services/ImportService.php

@@ -25,7 +25,7 @@ class ImportService
         }
         $start = 1;
         $key = self::CACHE_KEY . 'getIdRange:incr:byUserId:' . $userId . ':y-' . $year . ':m-' . $month . ':d-' . $day;
-        $incr = Cache::increment($key, random_int(3, 19));
+        $incr = Cache::increment($key, random_int(5, 19));
         if($incr > 999) {
             $daysInMonth = now()->parse($day . '-' . $month . '-' . $year)->daysInMonth;
 
@@ -64,7 +64,7 @@ class ImportService
             Cache::forget($key);
         }
         return intval(Cache::remember($key, 21600, function() use($profileId) {
-            return ImportPost::whereProfileId($profileId)->count();
+            return ImportPost::whereProfileId($profileId)->whereSkipMissingMedia(false)->count();
         }));
     }
 
@@ -73,6 +73,7 @@ class ImportService
         $key = self::CACHE_KEY . 'attemptsByProfileId:' . $profileId;
         return intval(Cache::remember($key, 21600, function() use($profileId) {
             return ImportPost::whereProfileId($profileId)
+                ->whereSkipMissingMedia(false)
                 ->get()
                 ->groupBy(function($item) {
                     return $item->created_at->format('Y-m-d');
@@ -86,4 +87,19 @@ class ImportService
         $key = self::CACHE_KEY . 'attemptsByProfileId:' . $profileId;
         return Cache::forget($key);
     }
+
+    public static function getImportedFiles($profileId, $refresh = false)
+    {
+        $key = self::CACHE_KEY . 'importedPostsByProfileId:' . $profileId;
+        if($refresh) {
+            Cache::forget($key);
+        }
+        return Cache::remember($key, 21600, function() use($profileId) {
+            return ImportPost::whereProfileId($profileId)
+                ->get()
+                ->map(function($ip) {
+                    return collect($ip->media)->map(function($m) { return $m['uri']; });
+                })->flatten();
+        });
+    }
 }

+ 1 - 0
database/migrations/2023_06_10_031634_create_import_posts_table.php

@@ -29,6 +29,7 @@ return new class extends Migration
             $table->bigInteger('status_id')->unsigned()->nullable()->unique()->index();
             $table->timestamp('creation_date')->nullable();
             $table->json('metadata')->nullable();
+            $table->boolean('skip_missing_media')->default(false)->index();
             $table->unique(['user_id', 'post_hash']);
             $table->unique(['user_id', 'creation_year', 'creation_month', 'creation_day', 'creation_id'], 'import_posts_uid_phash_unique');
             $table->timestamps();