Explorar o código

Update ApiV1Controller, improve follow count cache invalidation

Daniel Supernault %!s(int64=3) %!d(string=hai) anos
pai
achega
4b6effb9c8
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      app/Http/Controllers/Api/ApiV1Controller.php

+ 10 - 1
app/Http/Controllers/Api/ApiV1Controller.php

@@ -662,6 +662,8 @@ class ApiV1Controller extends Controller
 		Cache::forget('profile:follower_count:'.$user->profile_id);
 		Cache::forget('profile:follower_count:'.$user->profile_id);
 		Cache::forget('profile:following_count:'.$target->id);
 		Cache::forget('profile:following_count:'.$target->id);
 		Cache::forget('profile:following_count:'.$user->profile_id);
 		Cache::forget('profile:following_count:'.$user->profile_id);
+		AccountService::del($user->profile_id);
+		AccountService::del($target->id);
 
 
 		$res = RelationshipService::get($user->profile_id, $target->id);
 		$res = RelationshipService::get($user->profile_id, $target->id);
 
 
@@ -685,7 +687,6 @@ class ApiV1Controller extends Controller
 			->whereNull('status')
 			->whereNull('status')
 			->findOrFail($id);
 			->findOrFail($id);
 
 
-
 		$private = (bool) $target->is_private;
 		$private = (bool) $target->is_private;
 		$remote = (bool) $target->domain;
 		$remote = (bool) $target->domain;
 
 
@@ -705,6 +706,8 @@ class ApiV1Controller extends Controller
 			abort(400, 'You can only follow or unfollow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
 			abort(400, 'You can only follow or unfollow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
 		}
 		}
 
 
+		$user->profile->decrement('following_count');
+
 		FollowRequest::whereFollowerId($user->profile_id)
 		FollowRequest::whereFollowerId($user->profile_id)
 			->whereFollowingId($target->id)
 			->whereFollowingId($target->id)
 			->delete();
 			->delete();
@@ -725,6 +728,12 @@ 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);
+		AccountService::del($user->profile_id);
+		AccountService::del($target->id);
 
 
 		$res = RelationshipService::get($user->profile_id, $target->id);
 		$res = RelationshipService::get($user->profile_id, $target->id);