mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update AccountTransformer, cache status count
This commit is contained in:
parent
339a0a3882
commit
377394f0f2
4 changed files with 17 additions and 30 deletions
|
@ -347,6 +347,7 @@ class InternalApiController extends Controller
|
|||
|
||||
NewStatusPipeline::dispatch($status);
|
||||
Cache::forget('user:account:id:'.$profile->user_id);
|
||||
Cache::forget('profile:status_count:'.$profile->id);
|
||||
return $status->url();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,6 +197,7 @@ class StatusController extends Controller
|
|||
$status->type = (new self)::mimeTypeCheck($mimes);
|
||||
$status->save();
|
||||
|
||||
Cache::forget('profile:status_count:'.$profile->id);
|
||||
NewStatusPipeline::dispatch($status);
|
||||
|
||||
// TODO: Send to subscribers
|
||||
|
@ -215,6 +216,7 @@ class StatusController extends Controller
|
|||
$status = Status::findOrFail($request->input('item'));
|
||||
|
||||
if ($status->profile_id === Auth::user()->profile->id || Auth::user()->is_admin == true) {
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
StatusDelete::dispatch($status);
|
||||
}
|
||||
if($request->wantsJson()) {
|
||||
|
|
|
@ -125,7 +125,7 @@ class Profile extends Model
|
|||
|
||||
public function avatarUrl()
|
||||
{
|
||||
$url = Cache::remember("avatar:{$this->id}", now()->addYears(1), function () {
|
||||
$url = Cache::remember('avatar:'.$this->id, now()->addYears(1), function () {
|
||||
$avatar = $this->avatar;
|
||||
$path = $avatar->media_path;
|
||||
$version = hash('sha256', $avatar->change_count);
|
||||
|
@ -139,36 +139,20 @@ class Profile extends Model
|
|||
|
||||
public function statusCount()
|
||||
{
|
||||
return $this->statuses()
|
||||
->getQuery()
|
||||
->whereHas('media')
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
->count();
|
||||
return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
|
||||
return $this->statuses()
|
||||
->getQuery()
|
||||
->whereHas('media')
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
->count();
|
||||
});
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public function recommendFollowers()
|
||||
{
|
||||
$follows = $this->following()->pluck('followers.id');
|
||||
$following = $this->following()
|
||||
->orderByRaw('rand()')
|
||||
->take(3)
|
||||
->pluck('following_id');
|
||||
$following->push(Auth::id());
|
||||
$following = Follower::whereNotIn('profile_id', $follows)
|
||||
->whereNotIn('following_id', $following)
|
||||
->whereNotIn('following_id', $follows)
|
||||
->whereIn('profile_id', $following)
|
||||
->orderByRaw('rand()')
|
||||
->distinct('id')
|
||||
->limit(3)
|
||||
->pluck('following_id');
|
||||
$recommended = [];
|
||||
foreach ($following as $follow) {
|
||||
$recommended[] = self::findOrFail($follow);
|
||||
}
|
||||
|
||||
return $recommended;
|
||||
return collect([]);
|
||||
}
|
||||
|
||||
public function keyId()
|
||||
|
|
|
@ -19,7 +19,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
|
|||
'created_at' => null,
|
||||
'followers_count' => $profile->followerCount(),
|
||||
'following_count' => $profile->followingCount(),
|
||||
'statuses_count' => $profile->statusCount(),
|
||||
'statuses_count' => (int) $profile->statusCount(),
|
||||
'note' => $profile->bio,
|
||||
'url' => $profile->url(),
|
||||
'avatar' => $profile->avatarUrl(),
|
||||
|
@ -30,7 +30,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
|
|||
'moved' => null,
|
||||
'fields' => null,
|
||||
'bot' => null,
|
||||
'website' => $profile->website,
|
||||
'website' => null,
|
||||
'software' => 'pixelfed',
|
||||
'is_admin' => (bool) $is_admin
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue