diff --git a/app/Services/FollowerService.php b/app/Services/FollowerService.php new file mode 100644 index 000000000..4c0826114 --- /dev/null +++ b/app/Services/FollowerService.php @@ -0,0 +1,58 @@ +profile = $profile; + $this->follower_prefix = config('cache.prefix').':profile:followers:'.$profile->id; + $this->following_prefix = config('cache.prefix').':profile:following:'.$profile->id; + return $this; + } + + public function followers($limit = 100, $offset = 0) + { + if(Redis::llen($this->follower_prefix) == 0) { + $followers = $this->profile->followers; + $followers->map(function($i) { + Redis::lpush($this->follower_prefix, $i->id); + }); + return $followers; + } else { + return Redis::lrange($this->follower_prefix, $offset, $limit); + } + } + + + public function following($limit = 100, $offset = 0) + { + if(Redis::llen($this->following_prefix) == 0) { + $following = $this->profile->following; + $following->map(function($i) { + Redis::lpush($this->following_prefix, $i->id); + }); + return $following; + } else { + return Redis::lrange($this->following_prefix, $offset, $limit); + } + } + +} \ No newline at end of file