mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update Status model, refactor liked and shared methods to fix cache invalidation bug
This commit is contained in:
parent
2598520bbe
commit
f05c3b66fc
1 changed files with 15 additions and 14 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue