Update delete pipelines

pull/4002/head
Daniel Supernault 3 years ago
parent aa32eb8780
commit 1cdc0fe8ed
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7

@ -50,6 +50,10 @@ use App\{
UserFilter, UserFilter,
UserSetting, UserSetting,
}; };
use App\Models\Conversation;
use App\Models\Poll;
use App\Models\PollVote;
use App\Models\Portfolio;
use App\Models\UserPronoun; use App\Models\UserPronoun;
class DeleteAccountPipeline implements ShouldQueue class DeleteAccountPipeline implements ShouldQueue
@ -59,6 +63,9 @@ class DeleteAccountPipeline implements ShouldQueue
protected $user; protected $user;
public $timeout = 900; public $timeout = 900;
public $tries = 3;
public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
public function __construct(User $user) public function __construct(User $user)
{ {
@ -68,160 +75,108 @@ class DeleteAccountPipeline implements ShouldQueue
public function handle() public function handle()
{ {
$user = $this->user; $user = $this->user;
$profile = $user->profile;
$id = $user->profile_id;
$this->deleteUserColumns($user); $this->deleteUserColumns($user);
AccountService::del($user->profile_id); AccountService::del($user->profile_id);
DB::transaction(function() use ($user) { AccountLog::whereItemType('App\User')->whereItemId($user->id)->forceDelete();
AccountLog::whereItemType('App\User')->whereItemId($user->id)->forceDelete();
});
DB::transaction(function() use ($user) { AccountInterstitial::whereUserId($user->id)->delete();
AccountInterstitial::whereUserId($user->id)->delete();
});
DB::transaction(function() use ($user) { // Delete Avatar
if($user->profile) { $profile->avatar->forceDelete();
$avatar = $user->profile->avatar;
$path = $avatar->media_path;
if(!in_array($path, [
'public/avatars/default.jpg',
'public/avatars/default.png'
])) {
if(config('pixelfed.cloud_storage')) {
$disk = Storage::disk(config('filesystems.cloud'));
if($disk->exists($path)) {
$disk->delete($path);
}
}
$disk = Storage::disk(config('filesystems.local'));
if($disk->exists($path)) {
$disk->delete($path);
}
}
$avatar->forceDelete(); // Delete Poll Votes
} PollVote::whereProfileId($id)->delete();
$id = $user->profile_id; // Delete Polls
Poll::whereProfileId($id)->delete();
ImportData::whereProfileId($id) // Delete Portfolio
->cursor() Portfolio::whereProfileId($id)->delete();
->each(function($data) {
$path = storage_path('app/'.$data->path);
if(is_file($path)) {
unlink($path);
}
$data->delete();
});
ImportJob::whereProfileId($id)
->cursor()
->each(function($data) {
$path = storage_path('app/'.$data->media_json);
if(is_file($path)) {
unlink($path);
}
$data->delete();
});
MediaTag::whereProfileId($id)->delete();
Bookmark::whereProfileId($id)->forceDelete();
EmailVerification::whereUserId($user->id)->forceDelete();
StatusHashtag::whereProfileId($id)->delete();
DirectMessage::whereFromId($id)->orWhere('to_id', $id)->delete();
StatusArchived::whereProfileId($id)->delete();
UserPronoun::whereProfileId($id)->delete();
FollowRequest::whereFollowingId($id)
->orWhere('follower_id', $id)
->forceDelete();
Follower::whereProfileId($id)
->orWhere('following_id', $id)
->each(function($follow) {
FollowerService::remove($follow->profile_id, $follow->following_id);
$follow->delete();
});
FollowerService::delCache($id);
Like::whereProfileId($id)->forceDelete();
});
DB::transaction(function() use ($user) { ImportData::whereProfileId($id)
$pid = $this->user->profile_id; ->cursor()
->each(function($data) {
StoryView::whereProfileId($pid)->delete(); $path = storage_path('app/'.$data->path);
$stories = Story::whereProfileId($pid)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) { if(is_file($path)) {
unlink($path); unlink($path);
} }
$story->forceDelete(); $data->delete();
}
}); });
DB::transaction(function() use ($user) { ImportJob::whereProfileId($id)
$medias = Media::whereUserId($user->id)->get(); ->cursor()
foreach($medias as $media) { ->each(function($data) {
if(config('pixelfed.cloud_storage')) { $path = storage_path('app/'.$data->media_json);
$disk = Storage::disk(config('filesystems.cloud')); if(is_file($path)) {
if($disk->exists($media->media_path)) { unlink($path);
$disk->delete($media->media_path);
}
if($disk->exists($media->thumbnail_path)) {
$disk->delete($media->thumbnail_path);
}
}
$disk = Storage::disk(config('filesystems.local'));
if($disk->exists($media->media_path)) {
$disk->delete($media->media_path);
}
if($disk->exists($media->thumbnail_path)) {
$disk->delete($media->thumbnail_path);
} }
$media->forceDelete(); $data->delete();
}
}); });
DB::transaction(function() use ($user) { MediaTag::whereProfileId($id)->delete();
Mention::whereProfileId($user->profile_id)->forceDelete(); Bookmark::whereProfileId($id)->forceDelete();
Notification::whereProfileId($user->profile_id) EmailVerification::whereUserId($user->id)->forceDelete();
->orWhere('actor_id', $user->profile_id) StatusHashtag::whereProfileId($id)->delete();
->forceDelete(); DirectMessage::whereFromId($id)->orWhere('to_id', $id)->delete();
}); Conversation::whereFromId($id)->orWhere('to_id', $id)->delete();
StatusArchived::whereProfileId($id)->delete();
DB::transaction(function() use ($user) { UserPronoun::whereProfileId($id)->delete();
$collections = Collection::whereProfileId($user->profile_id)->get(); FollowRequest::whereFollowingId($id)
foreach ($collections as $collection) { ->orWhere('follower_id', $id)
$collection->items()->delete(); ->forceDelete();
$collection->delete(); Follower::whereProfileId($id)
->orWhere('following_id', $id)
->each(function($follow) {
FollowerService::remove($follow->profile_id, $follow->following_id);
$follow->delete();
});
FollowerService::delCache($id);
Like::whereProfileId($id)->forceDelete();
Mention::whereProfileId($id)->forceDelete();
StoryView::whereProfileId($id)->delete();
$stories = Story::whereProfileId($id)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) {
unlink($path);
} }
Contact::whereUserId($user->id)->delete(); $story->forceDelete();
HashtagFollow::whereUserId($user->id)->delete(); }
OauthClient::whereUserId($user->id)->delete();
DB::table('oauth_access_tokens')->whereUserId($user->id)->delete(); UserDevice::whereUserId($user->id)->forceDelete();
DB::table('oauth_auth_codes')->whereUserId($user->id)->delete(); UserFilter::whereUserId($user->id)->forceDelete();
ProfileSponsor::whereProfileId($user->profile_id)->delete(); UserSetting::whereUserId($user->id)->forceDelete();
});
Mention::whereProfileId($id)->forceDelete();
DB::transaction(function() use ($user) { Notification::whereProfileId($id)
Status::whereProfileId($user->profile_id)->forceDelete(); ->orWhere('actor_id', $id)
Report::whereUserId($user->id)->forceDelete(); ->forceDelete();
PublicTimelineService::warmCache(true, 400);
$this->deleteProfile($user); $collections = Collection::whereProfileId($id)->get();
}); foreach ($collections as $collection) {
} $collection->items()->delete();
$collection->delete();
protected function deleteProfile($user) { }
DB::transaction(function() use ($user) { Contact::whereUserId($user->id)->delete();
Profile::whereUserId($user->id)->delete(); HashtagFollow::whereUserId($user->id)->delete();
$this->deleteUserSettings($user); OauthClient::whereUserId($user->id)->delete();
}); DB::table('oauth_access_tokens')->whereUserId($user->id)->delete();
} DB::table('oauth_auth_codes')->whereUserId($user->id)->delete();
ProfileSponsor::whereProfileId($id)->delete();
protected function deleteUserSettings($user) {
Status::whereProfileId($id)->chunk(50, function($statuses) {
DB::transaction(function() use ($user) { foreach($statuses as $status) {
UserDevice::whereUserId($user->id)->forceDelete(); StatusDelete::dispatch($status)->onQueue('high');
UserFilter::whereUserId($user->id)->forceDelete(); }
UserSetting::whereUserId($user->id)->forceDelete(); });
});
Report::whereUserId($user->id)->forceDelete();
PublicTimelineService::warmCache(true, 400);
Profile::whereUserId($user->id)->delete();
} }
protected function deleteUserColumns($user) protected function deleteUserColumns($user)

@ -39,6 +39,7 @@ use App\{
ReportLog, ReportLog,
StatusHashtag, StatusHashtag,
Status, Status,
StatusView,
Story, Story,
StoryView, StoryView,
User, User,
@ -46,6 +47,10 @@ use App\{
UserFilter, UserFilter,
UserSetting, UserSetting,
}; };
use App\Models\Conversation;
use App\Models\Poll;
use App\Models\PollVote;
use App\Services\AccountService;
class DeleteRemoteProfilePipeline implements ShouldQueue class DeleteRemoteProfilePipeline implements ShouldQueue
{ {
@ -53,6 +58,11 @@ class DeleteRemoteProfilePipeline implements ShouldQueue
protected $profile; protected $profile;
public $timeout = 900;
public $tries = 3;
public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
public function __construct(Profile $profile) public function __construct(Profile $profile)
{ {
$this->profile = $profile; $this->profile = $profile;
@ -61,80 +71,85 @@ class DeleteRemoteProfilePipeline implements ShouldQueue
public function handle() public function handle()
{ {
$profile = $this->profile; $profile = $this->profile;
$pid = $profile->id;
if($profile->domain == null || $profile->private_key) { if($profile->domain == null || $profile->private_key) {
return; return;
} }
DB::transaction(function() use ($profile) { $profile->status = 'delete';
$profile->avatar->forceDelete(); $profile->save();
$id = $profile->id; AccountService::del($pid);
MediaTag::whereProfileId($id)->delete();
StatusHashtag::whereProfileId($id)->delete();
DirectMessage::whereFromId($id)->delete();
FollowRequest::whereFollowingId($id)
->orWhere('follower_id', $id)
->forceDelete();
Follower::whereProfileId($id)
->orWhere('following_id', $id)
->forceDelete();
Like::whereProfileId($id)->forceDelete();
});
DB::transaction(function() use ($profile) { // Delete statuses
$pid = $profile->id; Status::whereProfileId($pid)
StoryView::whereProfileId($pid)->delete(); ->chunk(50, function($statuses) {
$stories = Story::whereProfileId($pid)->get(); foreach($statuses as $status) {
foreach($stories as $story) { DeleteRemoteStatusPipeline::dispatch($status)->onQueue('delete');
$path = storage_path('app/'.$story->path);
if(is_file($path)) {
unlink($path);
} }
$story->forceDelete();
}
}); });
DB::transaction(function() use ($profile) { // Delete Poll Votes
$medias = Media::whereProfileId($profile->id)->get(); PollVote::whereProfileId($pid)->delete();
foreach($medias as $media) {
$path = storage_path('app/'.$media->media_path); // Delete Polls
$thumb = storage_path('app/'.$media->thumbnail_path); Poll::whereProfileId($pid)->delete();
if(is_file($path)) {
unlink($path); // Delete Avatar
} $profile->avatar->forceDelete();
if(is_file($thumb)) {
unlink($thumb); // Delete media tags
} MediaTag::whereProfileId($pid)->delete();
$media->forceDelete();
// Delete DMs
DirectMessage::whereFromId($pid)->orWhere('to_id', $pid)->delete();
Conversation::whereFromId($pid)->orWhere('to_id', $pid)->delete();
// Delete FollowRequests
FollowRequest::whereFollowingId($pid)
->orWhere('follower_id', $pid)
->delete();
// Delete relationships
Follower::whereProfileId($pid)
->orWhere('following_id', $pid)
->delete();
// Delete likes
Like::whereProfileId($pid)->forceDelete();
// Delete Story Views + Stories
StoryView::whereProfileId($pid)->delete();
$stories = Story::whereProfileId($pid)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) {
unlink($path);
} }
}); $story->forceDelete();
}
DB::transaction(function() use ($profile) { // Delete mutes/blocks
Mention::whereProfileId($profile->id)->forceDelete(); UserFilter::whereFilterableType('App\Profile')->whereFilterableId($pid)->delete();
Notification::whereProfileId($profile->id)
->orWhere('actor_id', $profile->id)
->forceDelete();
});
DB::transaction(function() use ($profile) { // Delete mentions
Status::whereProfileId($profile->id) Mention::whereProfileId($pid)->forceDelete();
->cursor()
->each(function($status) {
AccountInterstitial::where('item_type', 'App\Status')
->where('item_id', $status->id)
->delete();
$status->forceDelete();
});
Report::whereProfileId($profile->id)->forceDelete();
$this->deleteProfile($profile);
});
}
protected function deleteProfile($profile) { // Delete notifications
DB::transaction(function() use ($profile) { Notification::whereProfileId($pid)
Profile::findOrFail($profile->id)->delete(); ->orWhere('actor_id', $pid)
}); ->chunk(50, function($notifications) {
foreach($notifications as $n) {
$n->forceDelete();
}
});
// Delete reports
Report::whereProfileId($profile->id)->orWhere('reported_profile_id')->forceDelete();
// Delete profile
Profile::findOrFail($profile->id)->delete();
return;
} }
} }

@ -19,10 +19,12 @@ use App\Status;
use App\StatusHashtag; use App\StatusHashtag;
use App\StatusView; use App\StatusView;
use App\Notification; use App\Notification;
use App\Services\AccountService;
use App\Services\NetworkTimelineService; use App\Services\NetworkTimelineService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Jobs\ProfilePipeline\DecrementPostCount;
use App\Jobs\MediaPipeline\MediaDeletePipeline; use App\Jobs\MediaPipeline\MediaDeletePipeline;
use Cache;
class DeleteRemoteStatusPipeline implements ShouldQueue class DeleteRemoteStatusPipeline implements ShouldQueue
{ {
@ -30,9 +32,10 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
protected $status; protected $status;
public $timeout = 300; public $timeout = 30;
public $tries = 3; public $tries = 2;
public $maxExceptions = 1; public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
/** /**
* Create a new job instance. * Create a new job instance.
@ -41,7 +44,7 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
*/ */
public function __construct(Status $status) public function __construct(Status $status)
{ {
$this->status = $status->withoutRelations(); $this->status = $status;
} }
/** /**
@ -53,9 +56,12 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
{ {
$status = $this->status; $status = $this->status;
if(AccountService::get($status->profile_id, true)) {
DecrementPostCount::dispatch($status->profile_id)->onQueue('feed');
}
NetworkTimelineService::del($status->id); NetworkTimelineService::del($status->id);
StatusService::del($status->id, true); Cache::forget(StatusService::key($status->id));
DecrementPostCount::dispatchNow($status->profile_id);
Bookmark::whereStatusId($status->id)->delete(); Bookmark::whereStatusId($status->id)->delete();
Notification::whereItemType('App\Status') Notification::whereItemType('App\Status')
->whereItemId($status->id) ->whereItemId($status->id)
@ -73,6 +79,7 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
StatusHashtag::whereStatusId($status->id)->delete(); StatusHashtag::whereStatusId($status->id)->delete();
StatusView::whereStatusId($status->id)->delete(); StatusView::whereStatusId($status->id)->delete();
Status::whereReblogOfId($status->id)->forceDelete(); Status::whereReblogOfId($status->id)->forceDelete();
$status->delete(); $status->forceDelete();
return 1;
} }
} }

@ -89,7 +89,7 @@ class StatusDelete implements ShouldQueue
Media::whereStatusId($status->id) Media::whereStatusId($status->id)
->get() ->get()
->each(function($media) { ->each(function($media) {
MediaDeletePipeline::dispatchNow($media); MediaDeletePipeline::dispatch($media)->onQueue('mmo');
}); });
if($status->in_reply_to_id) { if($status->in_reply_to_id) {

@ -65,7 +65,7 @@ class AvatarObserver
@unlink($path); @unlink($path);
} }
if($avatar->cdn_url && config_cache('pixelfed.cloud_storage')) { if(config_cache('pixelfed.cloud_storage')) {
$disk = Storage::disk(config('filesystems.cloud')); $disk = Storage::disk(config('filesystems.cloud'));
$base = Str::startsWith($avatar->media_path, 'cache/avatars/'); $base = Str::startsWith($avatar->media_path, 'cache/avatars/');
if($base && $disk->exists($avatar->media_path)) { if($base && $disk->exists($avatar->media_path)) {

@ -274,6 +274,6 @@ class MediaStorageService {
if(!$confirm) { if(!$confirm) {
return; return;
} }
MediaDeletePipeline::dispatch($media); MediaDeletePipeline::dispatch($media)->onQueue('mmo');
} }
} }

Loading…
Cancel
Save