From f05c3b66fc8aa5e959936fdb4e930b3c8cc040d1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 14 Feb 2021 22:35:31 -0700 Subject: [PATCH 1/2] Update Status model, refactor liked and shared methods to fix cache invalidation bug --- app/Status.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Status.php b/app/Status.php index 3b6f6120c..d9adae0ac 100644 --- a/app/Status.php +++ b/app/Status.php @@ -144,15 +144,16 @@ class Status extends Model public function liked() : bool { - if(Auth::check() == false) { + if(!Auth::check()) { return false; } - $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(); - }); + + $pid = Auth::user()->profile_id; + + return Like::select('status_id', 'profile_id') + ->whereStatusId($this->id) + ->whereProfileId($pid) + ->exists(); } public function likedBy() @@ -189,15 +190,15 @@ class Status extends Model public function shared() : bool { - if(Auth::check() == false) { + if(!Auth::check()) { return false; } - $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(); - }); + $pid = Auth::user()->profile_id; + + return $this->select('profile_id', 'reblog_of_id') + ->whereProfileId($pid) + ->whereReblogOfId($this->id) + ->exists(); } public function sharedBy() From 1b92f9f4551ad9c2343d2b46c47b2b72c58541a6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 14 Feb 2021 22:36:05 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c3432a71..85fe6caf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - Updated Embeds. Fix Profile + Status embeds, remove following count and improve cache invalidation and hidden follower counts. ([5ac9d0e8](https://github.com/pixelfed/pixelfed/commit/5ac9d0e8)) - Updated FederationController, return 404 for invalid webfinger addresses. Fixes ([#2647](https://github.com/pixelfed/pixelfed/issues/2647)). ([deb6f115](https://github.com/pixelfed/pixelfed/commit/deb6f115)) - Updated InboxPipeline, fail earlier for invalid public keys. Fixes ([#2648](https://github.com/pixelfed/pixelfed/issues/2648)). ([d1c5e9b8](https://github.com/pixelfed/pixelfed/commit/d1c5e9b8)) +- Updated Status model, refactor liked and shared methods to fix cache invalidation bug. ([f05c3b66](https://github.com/pixelfed/pixelfed/commit/f05c3b66)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)