1
0
Fork 0

Merge pull request #1357 from pixelfed/frontend-ui-refactor

Update AccountTransformer, cache status count
This commit is contained in:
daniel 2019-06-05 01:39:24 -06:00 committed by GitHub
commit a63498c22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 30 deletions

View File

@ -347,6 +347,7 @@ class InternalApiController extends Controller
NewStatusPipeline::dispatch($status); NewStatusPipeline::dispatch($status);
Cache::forget('user:account:id:'.$profile->user_id); Cache::forget('user:account:id:'.$profile->user_id);
Cache::forget('profile:status_count:'.$profile->id);
return $status->url(); return $status->url();
} }
} }

View File

@ -196,7 +196,8 @@ class StatusController extends Controller
} }
$status->type = (new self)::mimeTypeCheck($mimes); $status->type = (new self)::mimeTypeCheck($mimes);
$status->save(); $status->save();
Cache::forget('profile:status_count:'.$profile->id);
NewStatusPipeline::dispatch($status); NewStatusPipeline::dispatch($status);
// TODO: Send to subscribers // TODO: Send to subscribers
@ -215,6 +216,7 @@ class StatusController extends Controller
$status = Status::findOrFail($request->input('item')); $status = Status::findOrFail($request->input('item'));
if ($status->profile_id === Auth::user()->profile->id || Auth::user()->is_admin == true) { if ($status->profile_id === Auth::user()->profile->id || Auth::user()->is_admin == true) {
Cache::forget('profile:status_count:'.$status->profile_id);
StatusDelete::dispatch($status); StatusDelete::dispatch($status);
} }
if($request->wantsJson()) { if($request->wantsJson()) {

View File

@ -125,7 +125,7 @@ class Profile extends Model
public function avatarUrl() 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; $avatar = $this->avatar;
$path = $avatar->media_path; $path = $avatar->media_path;
$version = hash('sha256', $avatar->change_count); $version = hash('sha256', $avatar->change_count);
@ -139,36 +139,20 @@ class Profile extends Model
public function statusCount() public function statusCount()
{ {
return $this->statuses() return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
->getQuery() return $this->statuses()
->whereHas('media') ->getQuery()
->whereNull('in_reply_to_id') ->whereHas('media')
->whereNull('reblog_of_id') ->whereNull('in_reply_to_id')
->count(); ->whereNull('reblog_of_id')
->count();
});
} }
// deprecated
public function recommendFollowers() public function recommendFollowers()
{ {
$follows = $this->following()->pluck('followers.id'); return collect([]);
$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;
} }
public function keyId() public function keyId()

View File

@ -19,7 +19,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'created_at' => null, 'created_at' => null,
'followers_count' => $profile->followerCount(), 'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(), 'following_count' => $profile->followingCount(),
'statuses_count' => $profile->statusCount(), 'statuses_count' => (int) $profile->statusCount(),
'note' => $profile->bio, 'note' => $profile->bio,
'url' => $profile->url(), 'url' => $profile->url(),
'avatar' => $profile->avatarUrl(), 'avatar' => $profile->avatarUrl(),
@ -30,7 +30,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'moved' => null, 'moved' => null,
'fields' => null, 'fields' => null,
'bot' => null, 'bot' => null,
'website' => $profile->website, 'website' => null,
'software' => 'pixelfed', 'software' => 'pixelfed',
'is_admin' => (bool) $is_admin 'is_admin' => (bool) $is_admin
]; ];