From 9f928ae570a2b4cc5de9791e6a2d58a2b279f0ab Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:31:30 -0600 Subject: [PATCH 1/9] Update LikeController --- app/Http/Controllers/LikeController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index 2b87353d0..ef4ab26ee 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -32,20 +32,23 @@ class LikeController extends Controller $like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail(); $like->forceDelete(); $count--; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } } else { $like = new Like(); $like->profile_id = $profile->id; $like->status_id = $status->id; $like->save(); $count++; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } LikePipeline::dispatch($like); } - $likes = Like::whereProfileId($profile->id) - ->orderBy('id', 'desc') - ->take(1000) - ->pluck('status_id'); - if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; } else { From 84e01f1132fcbeeab1fb1cc1490ecf61b14ca39e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:47:38 -0600 Subject: [PATCH 2/9] Update StatusController --- app/Http/Controllers/StatusController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index fe2ac6468..1f3c119a7 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -259,7 +259,12 @@ class StatusController extends Controller $count++; SharePipeline::dispatch($share); } - + + if($count >= 0) { + $status->reblogs_count = $count; + $status->save(); + } + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count]; } else { From bed5cc74dee312c77e8212e9e53d90b2fda33144 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:47:57 -0600 Subject: [PATCH 3/9] Update LikeController --- app/Http/Controllers/LikeController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index ef4ab26ee..08e0a4212 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -20,10 +20,11 @@ class LikeController extends Controller public function store(Request $request) { $this->validate($request, [ - 'item' => 'required|integer|min:1', - ]); + 'item' => 'required|integer|min:1', + ]); - $profile = Auth::user()->profile; + $user = Auth::user(); + $profile = $user->profile; $status = Status::withCount('likes')->findOrFail($request->input('item')); $count = $status->likes_count; @@ -49,6 +50,8 @@ class LikeController extends Controller LikePipeline::dispatch($like); } + Cache::forget('status:'.$status->id.':likedby:userid:'.$user->id); + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; } else { From f98c7caff6258f33c80c1f55691d946ee7a3f8da Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:48:40 -0600 Subject: [PATCH 4/9] Update Status model --- app/Status.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Status.php b/app/Status.php index f29e88e04..2e2470e6f 100644 --- a/app/Status.php +++ b/app/Status.php @@ -150,8 +150,10 @@ class Status extends Model if(Auth::check() == false) { return false; } - $profile = Auth::user()->profile; - return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + return Cache::remember('status:'.$this->id.':likedby:userid:'.Auth::id(), now()->addHours(30), function() { + $profile = Auth::user()->profile; + return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + }); } public function likedBy() From 5204aa2c1c693568f76ffcceb77129f8550130d7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:01:36 -0600 Subject: [PATCH 5/9] Update Api StatusTransformer --- app/Transformer/Api/StatusTransformer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Transformer/Api/StatusTransformer.php b/app/Transformer/Api/StatusTransformer.php index c74f4ed61..1c033c1f1 100644 --- a/app/Transformer/Api/StatusTransformer.php +++ b/app/Transformer/Api/StatusTransformer.php @@ -27,8 +27,8 @@ class StatusTransformer extends Fractal\TransformerAbstract 'content' => $status->rendered ?? $status->caption, 'created_at' => $status->created_at->format('c'), 'emojis' => [], - 'reblogs_count' => $status->shares()->count(), - 'favourites_count' => $status->likes()->count(), + 'reblogs_count' => $status->reblogs_count != 0 ? $status->reblogs_count: $status->shares()->count(), + 'favourites_count' => $status->likes_count != 0 ? $status->likes_count: $status->likes()->count(), 'reblogged' => $status->shared(), 'favourited' => $status->liked(), 'muted' => null, @@ -47,7 +47,7 @@ class StatusTransformer extends Fractal\TransformerAbstract 'comments_disabled' => $status->comments_disabled ? true : false, 'thread' => false, 'replies' => [], - 'parent' => $status->parent() ? $this->transform($status->parent()) : [], + 'parent' => [], ]; } From 4f25c73d59b7896de0d34b9a22339c162750d520 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:06:22 -0600 Subject: [PATCH 6/9] Update Activity.vue --- resources/assets/js/components/Activity.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/assets/js/components/Activity.vue b/resources/assets/js/components/Activity.vue index 3bcdac296..c237ee61f 100644 --- a/resources/assets/js/components/Activity.vue +++ b/resources/assets/js/components/Activity.vue @@ -225,6 +225,7 @@ export default { break; case 'like': case 'favourite': + case 'comment': return n.status.url; break; } From e98107fd5e409f93c73e81d422a5b1cea4a37ad8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:07:21 -0600 Subject: [PATCH 7/9] Update compiled assets --- public/js/activity.js | Bin 7144 -> 7158 bytes public/mix-manifest.json | Bin 1033 -> 1033 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/public/js/activity.js b/public/js/activity.js index 7c8a688cfc8a6ec66f2b9dd30cb1986d7d45cd1d..6952e855bba84a849015613de5450561cca1a418 100644 GIT binary patch delta 25 gcmaE1{>^*?3lC3nVsWZca(-@ZYF^1^CZ1>f0D-{?fB*mh delta 12 Tcmexn{=$3%3(saDo+tbOB$fox diff --git a/public/mix-manifest.json b/public/mix-manifest.json index c92679d40e9a542472eb35cb9ff4959d0164659f..a6851bc80ba5aeb4d72916b250f7e823116a4779 100644 GIT binary patch delta 31 mcmeC==;WBNRwUIj#n{|9#lXza)F3%I#oXM~)O_PX4`u+D(+Oz+ delta 31 mcmeC==;WBNR>ac6BE>i*%_7w@CD|y&&@9o!IC Date: Tue, 18 Jun 2019 01:15:47 -0600 Subject: [PATCH 8/9] Update Status model --- app/Status.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Status.php b/app/Status.php index 2e2470e6f..769f0c719 100644 --- a/app/Status.php +++ b/app/Status.php @@ -150,9 +150,11 @@ class Status extends Model if(Auth::check() == false) { return false; } - return Cache::remember('status:'.$this->id.':likedby:userid:'.Auth::id(), now()->addHours(30), function() { - $profile = Auth::user()->profile; - return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count(); + $user = Auth::user(); + $id = $this->id; + return Cache::remember('status:'.$this->id.':likedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) { + $profile = $user->profile; + return Like::whereProfileId($profile->id)->whereStatusId($id)->count(); }); } @@ -193,9 +195,12 @@ class Status extends Model if(Auth::check() == false) { return false; } - $profile = Auth::user()->profile; - - return self::whereProfileId($profile->id)->whereReblogOfId($this->id)->count(); + $user = Auth::user(); + $id = $this->id; + return Cache::remember('status:'.$this->id.':sharedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) { + $profile = $user->profile; + return self::whereProfileId($profile->id)->whereReblogOfId($id)->count(); + }); } public function sharedBy() From 6095f4c9c713557c5ccc22c2699b796e6b4b9fda Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 01:16:10 -0600 Subject: [PATCH 9/9] Update StatusController --- app/Http/Controllers/StatusController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 1f3c119a7..136c3ba57 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -234,7 +234,8 @@ class StatusController extends Controller 'item' => 'required|integer|min:1', ]); - $profile = Auth::user()->profile; + $user = Auth::user(); + $profile = $user->profile; $status = Status::withCount('shares')->findOrFail($request->input('item')); $count = $status->shares_count; @@ -265,6 +266,8 @@ class StatusController extends Controller $status->save(); } + Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id); + if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count]; } else {