From de56b0f0789c49f52975ee9407fd756f4ce2dc36 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 17 Dec 2022 23:18:07 -0700 Subject: [PATCH 1/3] Update MediaStorageService, clear MediaService and StatusService caches after localToCloud --- app/Services/MediaStorageService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index 055afe645..f7be84fff 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -106,6 +106,8 @@ class MediaStorageService { $media->save(); if($media->status_id) { Cache::forget('status:transformer:media:attachments:' . $media->status_id); + MediaService::del($media->status_id); + StatusService::del($media->status_id, false); } } From 382d00d91f5bc980f4ae4392e0580d724128ed8a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 17 Dec 2022 23:20:34 -0700 Subject: [PATCH 2/3] Add CloudMediaMigrate command to migrate older local media to cloud storage --- app/Console/Commands/CloudMediaMigrate.php | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Console/Commands/CloudMediaMigrate.php diff --git a/app/Console/Commands/CloudMediaMigrate.php b/app/Console/Commands/CloudMediaMigrate.php new file mode 100644 index 000000000..b17214ee4 --- /dev/null +++ b/app/Console/Commands/CloudMediaMigrate.php @@ -0,0 +1,79 @@ +error('Cloud storage not enabled. Exiting...'); + return; + } + + $limit = $this->option('limit'); + $hugeMode = $this->option('huge'); + + if($limit > 500 && !$hugeMode) { + $this->error('Max limit exceeded, use a limit lower than 500 or run again with the --huge flag'); + return; + } + + $bar = $this->output->createProgressBar($limit); + $bar->start(); + + Media::whereNot('version', '4') + ->where('created_at', '<', now()->subDays(2)) + ->whereRemoteMedia(false) + ->whereNotNull(['status_id', 'profile_id']) + ->whereNull(['cdn_url', 'replicated_at']) + ->orderByDesc('size') + ->take($limit) + ->get() + ->each(function($media) use($bar) { + if(Storage::disk('local')->exists($media->media_path)) { + $this->totalSize = $this->totalSize + $media->size; + MediaStorageService::store($media); + } + $bar->advance(); + }); + + $bar->finish(); + $this->line(' '); + $this->info('Finished!'); + if($this->totalSize) { + $this->info('Uploaded ' . PrettyNumber::size($this->totalSize) . ' of media to cloud storage!'); + $this->line(' '); + $this->info('These files are still stored locally, and will be automatically removed.'); + } + return Command::SUCCESS; + } +} From 08da577d4b0f1afd18bcbf6b40e9f89ffcf7c2cc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 17 Dec 2022 23:21:16 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b5ebab8..a1e9bea87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ - Update InboxPipeline, dispatch Follow/Accept Follow jobs to follow queue ([f62d2494](https://github.com/pixelfed/pixelfed/commit/f62d2494)) - Add MediaS3GarbageCollector command to clear local media after uploaded to S3 disks after 12 hours ([b8c3f153](https://github.com/pixelfed/pixelfed/commit/b8c3f153)) - Update MediaS3GarbageCollector command, disable logging by default and optimize huge invocations ([a14af93b](https://github.com/pixelfed/pixelfed/commit/a14af93b)) +- Update MediaStorageService, clear MediaService and StatusService caches after localToCloud ([de56b0f0](https://github.com/pixelfed/pixelfed/commit/de56b0f0)) +- Add CloudMediaMigrate command to migrate older local media to cloud storage ([382d00d9](https://github.com/pixelfed/pixelfed/commit/382d00d9)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.4 (2022-10-04)](https://github.com/pixelfed/pixelfed/compare/v0.11.3...v0.11.4)