Explorar o código

Update StoryService

Daniel Supernault %!s(int64=3) %!d(string=hai) anos
pai
achega
6b0b2cfaa5
Modificáronse 1 ficheiros con 45 adicións e 0 borrados
  1. 45 0
      app/Services/StoryService.php

+ 45 - 0
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;
+	}
 }