|
|
|
|
@ -176,7 +176,16 @@ class StoryIndexService
|
|
|
|
|
$path = $story->path;
|
|
|
|
|
|
|
|
|
|
Redis::pipeline(function ($pipe) use (
|
|
|
|
|
$author, $sid, $score, $ttl, $duration, $overlays, $viewCount, $createdIso, $type, $path
|
|
|
|
|
$author,
|
|
|
|
|
$sid,
|
|
|
|
|
$score,
|
|
|
|
|
$ttl,
|
|
|
|
|
$duration,
|
|
|
|
|
$overlays,
|
|
|
|
|
$viewCount,
|
|
|
|
|
$createdIso,
|
|
|
|
|
$type,
|
|
|
|
|
$path
|
|
|
|
|
) {
|
|
|
|
|
$keyStory = $this->storyKey($sid);
|
|
|
|
|
$keyAuth = $this->authorKey($author);
|
|
|
|
|
@ -235,6 +244,36 @@ class StoryIndexService
|
|
|
|
|
Redis::expire($key, $finalTtl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Keep the cached following set in sync when a follow is created.
|
|
|
|
|
* Only touches the key if it already exists; otherwise the next carousel
|
|
|
|
|
* fetch hydrates from SQL and picks up the new follow anyway.
|
|
|
|
|
*/
|
|
|
|
|
public function addFollowing(int $followerId, int $followingId): void
|
|
|
|
|
{
|
|
|
|
|
$key = "following:{$followerId}";
|
|
|
|
|
|
|
|
|
|
if (! Redis::exists($key)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Redis::sadd($key, (string) $followingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Keep the cached following set in sync when a follow is removed.
|
|
|
|
|
*/
|
|
|
|
|
public function removeFollowing(int $followerId, int $followingId): void
|
|
|
|
|
{
|
|
|
|
|
$key = "following:{$followerId}";
|
|
|
|
|
|
|
|
|
|
if (! Redis::exists($key)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Redis::srem($key, (string) $followingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rebuildIndex(): array
|
|
|
|
|
{
|
|
|
|
|
$lockKey = $this->rebuildLockKey();
|
|
|
|
|
@ -331,7 +370,6 @@ class StoryIndexService
|
|
|
|
|
'message' => 'Story index and seen data rebuilt successfully',
|
|
|
|
|
'stats' => $stats,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
Redis::del($lockKey);
|
|
|
|
|
}
|
|
|
|
|
@ -657,7 +695,6 @@ class StoryIndexService
|
|
|
|
|
if (! $hasResults) {
|
|
|
|
|
Redis::pipeline(function ($pipe) use ($followingKey) {
|
|
|
|
|
$pipe->sadd($followingKey, '__empty__');
|
|
|
|
|
$pipe->srem($followingKey, '__empty__');
|
|
|
|
|
$pipe->expire($followingKey, 3600);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
|