Update LikePipeline jobs, fix likes_count calculation

This commit is contained in:
Daniel Supernault 2021-12-04 20:31:36 -07:00
parent a641d3a32c
commit fe64e18712
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 7 additions and 5 deletions

View file

@ -2,7 +2,7 @@
namespace App\Jobs\LikePipeline; namespace App\Jobs\LikePipeline;
use Cache, Log; use Cache, DB, Log;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use App\{Like, Notification}; use App\{Like, Notification};
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
@ -59,6 +59,9 @@ class LikePipeline implements ShouldQueue
return; return;
} }
$status->likes_count = DB::table('likes')->whereStatusId($status->id)->count();
$status->save();
StatusService::refresh($status->id); StatusService::refresh($status->id);
if($status->url && $actor->domain == null) { if($status->url && $actor->domain == null) {

View file

@ -2,7 +2,7 @@
namespace App\Jobs\LikePipeline; namespace App\Jobs\LikePipeline;
use Cache, Log; use Cache, DB, Log;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use App\{Like, Notification}; use App\{Like, Notification};
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
@ -59,8 +59,7 @@ class UnlikePipeline implements ShouldQueue
return; return;
} }
$count = $status->likes_count > 1 ? $status->likes_count : $status->likes()->count(); $status->likes_count = DB::table('likes')->whereStatusId($status->id)->count();
$status->likes_count = $count - 1;
$status->save(); $status->save();
StatusService::refresh($status->id); StatusService::refresh($status->id);