diff --git a/app/Services/StoryService.php b/app/Services/StoryService.php index cbdeb19f3..f44828899 100644 --- a/app/Services/StoryService.php +++ b/app/Services/StoryService.php @@ -3,6 +3,7 @@ namespace App\Services; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Storage; use App\Story; use App\StoryView; @@ -31,6 +32,18 @@ class StoryService return $res; } + public static function getById($id) + { + return Cache::remember(self::STORY_KEY . 'by-id:id-' . $id, 3600, function() use ($id) { + return Story::find($id); + }); + } + + public static function delById($id) + { + return Cache::forget(self::STORY_KEY . 'by-id:id-' . $id); + } + public static function getStories($id, $pid) { return Story::whereProfileId($id) @@ -114,4 +127,36 @@ class StoryService ]; }); } + + public static function rotateQueue() + { + return Redis::smembers('pf:stories:rotate-queue'); + } + + public static function addRotateQueue($id) + { + return Redis::sadd('pf:stories:rotate-queue', $id); + } + + public static function removeRotateQueue($id) + { + self::delById($id); + return Redis::srem('pf:stories:rotate-queue', $id); + } + + public static function reactIncrement($storyId, $profileId) + { + $key = 'pf:stories:react-counter:storyid-' . $storyId . ':profileid-' . $profileId; + if(Redis::get($key) == null) { + Redis::setex($key, 86400, 1); + } else { + return Redis::incr($key); + } + } + + public static function reactCounter($storyId, $profileId) + { + $key = 'pf:stories:react-counter:storyid-' . $storyId . ':profileid-' . $profileId; + return (int) Redis::get($key) ?? 0; + } }