forked from mirror/pixelfed
Merge pull request #2484 from pixelfed/staging
Update Profile model, improve counter caching
This commit is contained in:
commit
fb6fc66e8e
|
@ -127,6 +127,7 @@
|
||||||
- Updated reply/comment view, improve layout and include child reply. ([2eca670e](https://github.com/pixelfed/pixelfed/commit/2eca670e))
|
- Updated reply/comment view, improve layout and include child reply. ([2eca670e](https://github.com/pixelfed/pixelfed/commit/2eca670e))
|
||||||
- Updated Collections, add custom limit. ([048642be](https://github.com/pixelfed/pixelfed/commit/048642be))
|
- Updated Collections, add custom limit. ([048642be](https://github.com/pixelfed/pixelfed/commit/048642be))
|
||||||
- Updated AccountInterstitialController, add autospam type. ([c67f0c57](https://github.com/pixelfed/pixelfed/commit/c67f0c57))
|
- Updated AccountInterstitialController, add autospam type. ([c67f0c57](https://github.com/pixelfed/pixelfed/commit/c67f0c57))
|
||||||
|
- Updated Profile model, improve counter caching. ([4a14e970](https://github.com/pixelfed/pixelfed/commit/4a14e970))
|
||||||
|
|
||||||
## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9)
|
## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9)
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -376,6 +376,9 @@ class AccountController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cache::forget('profile:follower_count:'.$pid);
|
||||||
|
Cache::forget('profile:following_count:'.$pid);
|
||||||
|
|
||||||
return response()->json(['msg' => 'success'], 200);
|
return response()->json(['msg' => 'success'], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -468,6 +468,10 @@ class ApiV1Controller extends Controller
|
||||||
Cache::forget('api:local:exp:rec:'.$user->profile_id);
|
Cache::forget('api:local:exp:rec:'.$user->profile_id);
|
||||||
Cache::forget('user:account:id:'.$target->user_id);
|
Cache::forget('user:account:id:'.$target->user_id);
|
||||||
Cache::forget('user:account:id:'.$user->id);
|
Cache::forget('user:account:id:'.$user->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$target->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$user->profile_id);
|
||||||
|
Cache::forget('profile:following_count:'.$target->id);
|
||||||
|
Cache::forget('profile:following_count:'.$user->profile_id);
|
||||||
|
|
||||||
$resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
|
$resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
|
|
|
@ -115,6 +115,10 @@ class FollowerController extends Controller
|
||||||
Cache::forget('px:profile:followers-v1.3:'.$target->id);
|
Cache::forget('px:profile:followers-v1.3:'.$target->id);
|
||||||
Cache::forget('px:profile:following-v1.3:'.$user->id);
|
Cache::forget('px:profile:following-v1.3:'.$user->id);
|
||||||
Cache::forget('px:profile:following-v1.3:'.$target->id);
|
Cache::forget('px:profile:following-v1.3:'.$target->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$target->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$user->id);
|
||||||
|
Cache::forget('profile:following_count:'.$target->id);
|
||||||
|
Cache::forget('profile:following_count:'.$user->id);
|
||||||
|
|
||||||
return $target->url();
|
return $target->url();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,22 +64,52 @@ class Profile extends Model
|
||||||
|
|
||||||
public function followingCount($short = false)
|
public function followingCount($short = false)
|
||||||
{
|
{
|
||||||
$count = $this->following()->count();
|
$count = Cache::remember('profile:following_count:'.$this->id, now()->addMonths(1), function() {
|
||||||
if ($short) {
|
$count = $this->following_count;
|
||||||
return PrettyNumber::convert($count);
|
if($count) {
|
||||||
} else {
|
return $count;
|
||||||
|
}
|
||||||
|
$count = $this->following()->count();
|
||||||
|
$this->following_count = $count;
|
||||||
|
$this->save();
|
||||||
return $count;
|
return $count;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
return $short ? PrettyNumber::convert($count) : $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function followerCount($short = false)
|
public function followerCount($short = false)
|
||||||
{
|
{
|
||||||
$count = $this->followers()->count();
|
$count = Cache::remember('profile:follower_count:'.$this->id, now()->addMonths(1), function() {
|
||||||
if ($short) {
|
$count = $this->followers_count;
|
||||||
return PrettyNumber::convert($count);
|
if($count) {
|
||||||
} else {
|
return $count;
|
||||||
|
}
|
||||||
|
$count = $this->followers()->count();
|
||||||
|
$this->followers_count = $count;
|
||||||
|
$this->save();
|
||||||
return $count;
|
return $count;
|
||||||
}
|
});
|
||||||
|
return $short ? PrettyNumber::convert($count) : $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function statusCount()
|
||||||
|
{
|
||||||
|
return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
|
||||||
|
$count = $this->status_count;
|
||||||
|
if($count) {
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
$count = $this->statuses()
|
||||||
|
->getQuery()
|
||||||
|
->whereHas('media')
|
||||||
|
->whereNull('in_reply_to_id')
|
||||||
|
->whereNull('reblog_of_id')
|
||||||
|
->count();
|
||||||
|
$this->status_count = $count;
|
||||||
|
$this->save();
|
||||||
|
return $count;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function following()
|
public function following()
|
||||||
|
@ -148,18 +178,6 @@ class Profile extends Model
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function statusCount()
|
|
||||||
{
|
|
||||||
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
|
// deprecated
|
||||||
public function recommendFollowers()
|
public function recommendFollowers()
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Inbox
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$to = $activity['to'];
|
$to = $activity['to'];
|
||||||
$cc = $activity['cc'];
|
$cc = isset($activity['cc']) ? $activity['cc'] : [];
|
||||||
if(count($to) == 1 &&
|
if(count($to) == 1 &&
|
||||||
count($cc) == 0 &&
|
count($cc) == 0 &&
|
||||||
parse_url($to[0], PHP_URL_HOST) == config('pixelfed.domain.app')
|
parse_url($to[0], PHP_URL_HOST) == config('pixelfed.domain.app')
|
||||||
|
@ -342,6 +342,12 @@ class Inbox
|
||||||
'follower_id' => $actor->id,
|
'follower_id' => $actor->id,
|
||||||
'following_id' => $target->id
|
'following_id' => $target->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Cache::forget('profile:follower_count:'.$target->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$actor->id);
|
||||||
|
Cache::forget('profile:following_count:'.$target->id);
|
||||||
|
Cache::forget('profile:following_count:'.$actor->id);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$follower = new Follower;
|
$follower = new Follower;
|
||||||
$follower->profile_id = $actor->id;
|
$follower->profile_id = $actor->id;
|
||||||
|
@ -365,6 +371,10 @@ class Inbox
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
Helpers::sendSignedObject($target, $actor->inbox_url, $accept);
|
Helpers::sendSignedObject($target, $actor->inbox_url, $accept);
|
||||||
|
Cache::forget('profile:follower_count:'.$target->id);
|
||||||
|
Cache::forget('profile:follower_count:'.$actor->id);
|
||||||
|
Cache::forget('profile:following_count:'.$target->id);
|
||||||
|
Cache::forget('profile:following_count:'.$actor->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue