Skip to content

Commit

Permalink
Update TransformImports command, improve handling of imported posts t…
Browse files Browse the repository at this point in the history
…hat already exist or are from deleted accounts
  • Loading branch information
dansup committed Jun 26, 2023
1 parent b18f3fb commit 892907d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/ImportUploadGarbageCollection.php
Expand Up @@ -32,7 +32,7 @@ public function handle()
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;
Expand Down
28 changes: 14 additions & 14 deletions app/Console/Commands/TransformImports.php
Expand Up @@ -54,22 +54,22 @@ public function handle()
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);
Expand Down
5 changes: 5 additions & 0 deletions app/Observers/StatusObserver.php
Expand Up @@ -5,6 +5,7 @@
use App\Status;
use App\Services\ProfileStatusService;
use Cache;
use App\Services\ImportService;

class StatusObserver
{
Expand Down Expand Up @@ -56,6 +57,10 @@ public function deleted(Status $status)
}

ProfileStatusService::delete($status->profile_id, $status->id);

if($status->uri == null) {
ImportService::clearImportedFiles($status->profile_id);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/Services/ImportService.php
Expand Up @@ -102,4 +102,10 @@ public static function getImportedFiles($profileId, $refresh = false)
})->flatten();
});
}

public static function clearImportedFiles($profileId)
{
$key = self::CACHE_KEY . 'importedPostsByProfileId:' . $profileId;
return Cache::forget($key);
}
}

0 comments on commit 892907d

Please sign in to comment.