From 20a560bfd140f1f23e68ce57bb9d7e9e0073fb68 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 11 Nov 2023 07:23:11 -0700 Subject: [PATCH] Update FollowerService, add localFollowerIds method --- app/Services/FollowerService.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Services/FollowerService.php b/app/Services/FollowerService.php index 1c00a6f49..677507b03 100644 --- a/app/Services/FollowerService.php +++ b/app/Services/FollowerService.php @@ -19,6 +19,7 @@ class FollowerService const FOLLOWING_SYNC_KEY = 'pf:services:followers:sync-following:'; const FOLLOWING_KEY = 'pf:services:follow:following:id:'; const FOLLOWERS_KEY = 'pf:services:follow:followers:id:'; + const FOLLOWERS_LOCAL_KEY = 'pf:services:follow:local-follower-ids:'; public static function add($actor, $target, $refresh = true) { @@ -212,4 +213,15 @@ class FollowerService Cache::forget(self::FOLLOWERS_SYNC_KEY . $id); Cache::forget(self::FOLLOWING_SYNC_KEY . $id); } + + public static function localFollowerIds($pid, $limit = 0) + { + $key = self::FOLLOWERS_LOCAL_KEY . $pid; + $res = Cache::remember($key, 86400, function() use($pid) { + return DB::table('followers')->whereFollowingId($pid)->whereLocalProfile(true)->pluck('profile_id')->sort(); + }); + return $limit ? + $res->take($limit)->values()->toArray() : + $res->values()->toArray(); + } }