Merge pull request #3936 from pixelfed/staging

Dispatch follow accept/reject pipeline jobs to follow queue
This commit is contained in:
daniel 2022-12-12 20:45:13 -07:00 committed by GitHub
commit 5ec8bc7d98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 15 deletions

View file

@ -409,7 +409,7 @@ class AccountController extends Controller
AccountService::del($profile->id); AccountService::del($profile->id);
if($follower->domain != null && $follower->private_key === null) { if($follower->domain != null && $follower->private_key === null) {
FollowAcceptPipeline::dispatch($followRequest); FollowAcceptPipeline::dispatch($followRequest)->onQueue('follow');
} else { } else {
FollowPipeline::dispatch($follow); FollowPipeline::dispatch($follow);
$followRequest->delete(); $followRequest->delete();
@ -418,7 +418,7 @@ class AccountController extends Controller
case 'reject': case 'reject':
if($follower->domain != null && $follower->private_key === null) { if($follower->domain != null && $follower->private_key === null) {
FollowRejectPipeline::dispatch($followRequest); FollowRejectPipeline::dispatch($followRequest)->onQueue('follow');
} else { } else {
$followRequest->delete(); $followRequest->delete();
} }

View file

@ -673,15 +673,10 @@ class ApiV1Controller extends Controller
} }
// Rate limits, max 7500 followers per account // Rate limits, max 7500 followers per account
if($user->profile->following()->count() >= Follower::MAX_FOLLOWING) { if($user->profile->following_count && $user->profile->following_count >= Follower::MAX_FOLLOWING) {
abort(400, 'You cannot follow more than ' . Follower::MAX_FOLLOWING . ' accounts'); abort(400, 'You cannot follow more than ' . Follower::MAX_FOLLOWING . ' accounts');
} }
// Rate limits, follow 30 accounts per hour max
if($user->profile->following()->where('followers.created_at', '>', now()->subHour())->count() >= Follower::FOLLOW_PER_HOUR) {
abort(400, 'You can only follow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
}
if($private == true) { if($private == true) {
$follow = FollowRequest::firstOrCreate([ $follow = FollowRequest::firstOrCreate([
'follower_id' => $user->profile_id, 'follower_id' => $user->profile_id,
@ -761,11 +756,6 @@ class ApiV1Controller extends Controller
return $this->json($res); return $this->json($res);
} }
// Rate limits, follow 30 accounts per hour max
if($user->profile->following()->where('followers.updated_at', '>', now()->subHour())->count() >= Follower::FOLLOW_PER_HOUR) {
abort(400, 'You can only follow or unfollow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
}
if($user->profile->following_count) { if($user->profile->following_count) {
$user->profile->decrement('following_count'); $user->profile->decrement('following_count');
} }
@ -1266,7 +1256,7 @@ class ApiV1Controller extends Controller
AccountService::del($profile->id); AccountService::del($profile->id);
if($follower->domain != null && $follower->private_key === null) { if($follower->domain != null && $follower->private_key === null) {
FollowAcceptPipeline::dispatch($followRequest); FollowAcceptPipeline::dispatch($followRequest)->onQueue('follow');
} else { } else {
FollowPipeline::dispatch($follow); FollowPipeline::dispatch($follow);
$followRequest->delete(); $followRequest->delete();
@ -1304,7 +1294,7 @@ class ApiV1Controller extends Controller
$follower = $followRequest->follower; $follower = $followRequest->follower;
if($follower->domain != null && $follower->private_key === null) { if($follower->domain != null && $follower->private_key === null) {
FollowRejectPipeline::dispatch($followRequest); FollowRejectPipeline::dispatch($followRequest)->onQueue('follow');
} else { } else {
$followRequest->delete(); $followRequest->delete();
} }
@ -2511,6 +2501,7 @@ class ApiV1Controller extends Controller
$ids = $request->input('media_ids'); $ids = $request->input('media_ids');
$in_reply_to_id = $request->input('in_reply_to_id'); $in_reply_to_id = $request->input('in_reply_to_id');
$user = $request->user(); $user = $request->user();
$profile = $user->profile; $profile = $user->profile;