mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update StoryService
This commit is contained in:
parent
b32f4d91c4
commit
6b0b2cfaa5
1 changed files with 45 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue