From 892907d5d18a5b78661d001e5b7ebfa3189b0c94 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 26 Jun 2023 04:16:49 -0600 Subject: [PATCH] Update TransformImports command, improve handling of imported posts that already exist or are from deleted accounts --- .../ImportUploadGarbageCollection.php | 2 +- app/Console/Commands/TransformImports.php | 28 +++++++++---------- app/Observers/StatusObserver.php | 5 ++++ app/Services/ImportService.php | 6 ++++ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/ImportUploadGarbageCollection.php b/app/Console/Commands/ImportUploadGarbageCollection.php index cec323dcf..7d1ab24b5 100644 --- a/app/Console/Commands/ImportUploadGarbageCollection.php +++ b/app/Console/Commands/ImportUploadGarbageCollection.php @@ -32,7 +32,7 @@ class ImportUploadGarbageCollection extends Command return; } - $ips = ImportPost::whereNull('status_id')->whereSkipMissingMedia(true)->take(100)->get(); + $ips = ImportPost::whereNull('status_id')->where('skip_missing_media', true)->take(100)->get(); if(!$ips->count()) { return; diff --git a/app/Console/Commands/TransformImports.php b/app/Console/Commands/TransformImports.php index 3b9509387..cd63985ac 100644 --- a/app/Console/Commands/TransformImports.php +++ b/app/Console/Commands/TransformImports.php @@ -54,22 +54,22 @@ class TransformImports extends Command continue; } - $idk = ImportService::getId($ip->user_id, $ip->creation_year, $ip->creation_month, $ip->creation_day); - $exists = ImportPost::whereUserId($id)->where('filename', $ip->filename)->first(); - if($exists) { - $cYear = str_pad($exists->creation_year, 2, 0, STR_PAD_LEFT); - $cMonth = str_pad($exists->creation_month, 2, 0, STR_PAD_LEFT); - $cDay = str_pad($exists->creation_day, 2, 0, STR_PAD_LEFT); - if( $cYear == $idk['year'] && - $cMonth == $idk['month'] && - $cDay == $idk['day'] - ) { - $ip->skip_missing_media = true; - $ip->save(); - continue; - } + $exists = ImportPost::whereUserId($id) + ->whereNotNull('status_id') + ->where('filename', $ip->filename) + ->where('creation_year', $ip->creation_year) + ->where('creation_month', $ip->creation_month) + ->where('creation_day', $ip->creation_day) + ->exists(); + + if($exists == true) { + $ip->skip_missing_media = true; + $ip->save(); + continue; } + $idk = ImportService::getId($ip->user_id, $ip->creation_year, $ip->creation_month, $ip->creation_day); + if(Storage::exists('imports/' . $id . '/' . $ip->filename) === false) { ImportService::clearAttempts($profile->id); ImportService::getPostCount($profile->id, true); diff --git a/app/Observers/StatusObserver.php b/app/Observers/StatusObserver.php index 8d370b38e..99d6a89ff 100644 --- a/app/Observers/StatusObserver.php +++ b/app/Observers/StatusObserver.php @@ -5,6 +5,7 @@ namespace App\Observers; use App\Status; use App\Services\ProfileStatusService; use Cache; +use App\Services\ImportService; class StatusObserver { @@ -56,6 +57,10 @@ class StatusObserver } ProfileStatusService::delete($status->profile_id, $status->id); + + if($status->uri == null) { + ImportService::clearImportedFiles($status->profile_id); + } } /** diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 2ed43e73f..8ca12b445 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -102,4 +102,10 @@ class ImportService })->flatten(); }); } + + public static function clearImportedFiles($profileId) + { + $key = self::CACHE_KEY . 'importedPostsByProfileId:' . $profileId; + return Cache::forget($key); + } }