mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-03-04 02:28:08 +00:00
Update story garbage collection, handle non active stories and new ephemeral story media directory
This commit is contained in:
parent
71aeb8a25d
commit
c43f8bcce8
1 changed files with 106 additions and 82 deletions
|
@ -3,14 +3,10 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\{
|
use Illuminate\Support\Facades\DB;
|
||||||
DB,
|
use Illuminate\Support\Facades\Storage;
|
||||||
Storage
|
use App\Story;
|
||||||
};
|
use App\StoryView;
|
||||||
use App\{
|
|
||||||
Story,
|
|
||||||
StoryView
|
|
||||||
};
|
|
||||||
|
|
||||||
class StoryGC extends Command
|
class StoryGC extends Command
|
||||||
{
|
{
|
||||||
|
@ -52,9 +48,9 @@ class StoryGC extends Command
|
||||||
|
|
||||||
protected function directoryScan()
|
protected function directoryScan()
|
||||||
{
|
{
|
||||||
$day = now()->day;
|
$hour = now()->hour;
|
||||||
|
|
||||||
if($day != 3) {
|
if($hour !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +68,18 @@ class StoryGC extends Command
|
||||||
$this->deleteDirectory($dir);
|
$this->deleteDirectory($dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mh = hash('sha256', date('Y').'-.-'.date('m'));
|
||||||
|
$monthHash = date('Y').date('m').substr($mh, 0, 6).substr($mh, 58, 6);
|
||||||
|
$dirs = Storage::directories('public/_esm.t3');
|
||||||
|
|
||||||
|
foreach($dirs as $dir) {
|
||||||
|
$hash = last(explode('/', $dir));
|
||||||
|
if($hash != $monthHash) {
|
||||||
|
$this->info('Found directory to delete: ' . $dir);
|
||||||
|
$this->deleteDirectory($dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function deleteDirectory($path)
|
protected function deleteDirectory($path)
|
||||||
|
@ -86,7 +94,23 @@ class StoryGC extends Command
|
||||||
|
|
||||||
protected function deleteStories()
|
protected function deleteStories()
|
||||||
{
|
{
|
||||||
$stories = Story::where('created_at', '<', now()->subMinutes(1441))->take(50)->get();
|
$stories = Story::where('created_at', '>', now()->subMinutes(30))
|
||||||
|
->whereNull('active')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach($stories as $story) {
|
||||||
|
if(Storage::exists($story->path) == true) {
|
||||||
|
Storage::delete($story->path);
|
||||||
|
}
|
||||||
|
DB::transaction(function() use($story) {
|
||||||
|
StoryView::whereStoryId($story->id)->delete();
|
||||||
|
$story->delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$stories = Story::where('created_at', '<', now()
|
||||||
|
->subMinutes(1441))
|
||||||
|
->get();
|
||||||
|
|
||||||
if($stories->count() == 0) {
|
if($stories->count() == 0) {
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue