Skip to content

Commit

Permalink
Update FollowerService, add forget method to RelationshipService call…
Browse files Browse the repository at this point in the history
… to reduce load when mass purging
  • Loading branch information
dansup committed Aug 23, 2023
1 parent a04ba18 commit 347e4f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/Services/FollowerService.php
Expand Up @@ -20,10 +20,14 @@ class FollowerService
const FOLLOWING_KEY = 'pf:services:follow:following:id:';
const FOLLOWERS_KEY = 'pf:services:follow:followers:id:';

public static function add($actor, $target)
public static function add($actor, $target, $refresh = true)
{
$ts = (int) microtime(true);
RelationshipService::refresh($actor, $target);
if($refresh) {
RelationshipService::refresh($actor, $target);
} else {
RelationshipService::forget($actor, $target);
}
Redis::zadd(self::FOLLOWING_KEY . $actor, $ts, $target);
Redis::zadd(self::FOLLOWERS_KEY . $target, $ts, $actor);
Cache::forget('profile:following:' . $actor);
Expand Down
8 changes: 8 additions & 0 deletions app/Services/RelationshipService.php
Expand Up @@ -66,6 +66,14 @@ public static function refresh($aid, $tid)
return self::get($aid, $tid);
}

public static function forget($aid, $tid)
{
Cache::forget('pf:services:follower:audience:' . $aid);
Cache::forget('pf:services:follower:audience:' . $tid);
self::delete($tid, $aid);
self::delete($aid, $tid);
}

public static function defaultRelation($tid)
{
return [
Expand Down

0 comments on commit 347e4f5

Please sign in to comment.