diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 5216f3947..2ed43e73f 100644 --- a/app/Services/ImportService.php +++ b/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(); + }); + } } diff --git a/database/migrations/2023_06_10_031634_create_import_posts_table.php b/database/migrations/2023_06_10_031634_create_import_posts_table.php index eea0b5114..5bd186d67 100644 --- a/database/migrations/2023_06_10_031634_create_import_posts_table.php +++ b/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();