Update StoryController, show active self stories on home timeline

pull/4355/head
Daniel Supernault 2023-05-05 06:42:17 -06:00
rodzic 73429ac975
commit 633351f6dc
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 0DEF1C662C9033F7
2 zmienionych plików z 44 dodań i 19 usunięć

Wyświetl plik

@ -37,28 +37,53 @@ class StoryController extends StoryComposeController
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
if(config('database.default') == 'pgsql') { if(config('database.default') == 'pgsql') {
$s = Story::select('stories.*', 'followers.following_id') $s = Cache::remember('pf:stories:recent-by-id:' . $pid, 900, function() use($pid) {
->leftJoin('followers', 'followers.following_id', 'stories.profile_id') return Story::select('stories.*', 'followers.following_id')
->where('followers.profile_id', $pid) ->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
->where('stories.active', true) ->where('followers.profile_id', $pid)
->where('stories.active', true)
->get()
->map(function($s) {
$r = new \StdClass;
$r->id = $s->id;
$r->profile_id = $s->profile_id;
$r->type = $s->type;
$r->path = $s->path;
return $r;
})
->unique('profile_id');
});
} else {
$s = Cache::remember('pf:stories:recent-by-id:' . $pid, 900, function() use($pid) {
return Story::select('stories.*', 'followers.following_id')
->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
->where('followers.profile_id', $pid)
->where('stories.active', true)
->groupBy('followers.following_id')
->orderByDesc('id')
->get();
});
}
$self = Cache::remember('pf:stories:recent-self:' . $pid, 21600, function() use($pid) {
return Story::whereProfileId($pid)
->whereActive(true)
->orderByDesc('id')
->limit(1)
->get() ->get()
->map(function($s) { ->map(function($s) use($pid) {
$r = new \StdClass; $r = new \StdClass;
$r->id = $s->id; $r->id = $s->id;
$r->profile_id = $s->profile_id; $r->profile_id = $pid;
$r->type = $s->type; $r->type = $s->type;
$r->path = $s->path; $r->path = $s->path;
return $r; return $r;
}) });
->unique('profile_id'); });
} else {
$s = Story::select('stories.*', 'followers.following_id') if($self->count()) {
->leftJoin('followers', 'followers.following_id', 'stories.profile_id') $s->prepend($self->first());
->where('followers.profile_id', $pid)
->where('stories.active', true)
->groupBy('followers.following_id')
->orderByDesc('id')
->get();
} }
$res = $s->map(function($s) use($pid) { $res = $s->map(function($s) use($pid) {
@ -93,7 +118,7 @@ class StoryController extends StoryComposeController
$profile = Profile::findOrFail($id); $profile = Profile::findOrFail($id);
if($authed != $profile->id && !FollowerService::follows($authed, $profile->id)) { if($authed != $profile->id && !FollowerService::follows($authed, $profile->id)) {
return []; return abort([], 403);
} }
$stories = Story::whereProfileId($profile->id) $stories = Story::whereProfileId($profile->id)
@ -164,7 +189,6 @@ class StoryController extends StoryComposeController
$publicOnly = (bool) $profile->followedBy($authed); $publicOnly = (bool) $profile->followedBy($authed);
abort_if(!$publicOnly, 403); abort_if(!$publicOnly, 403);
$v = StoryView::firstOrCreate([ $v = StoryView::firstOrCreate([
'story_id' => $id, 'story_id' => $id,
'profile_id' => $authed->id 'profile_id' => $authed->id

Wyświetl plik

@ -95,7 +95,8 @@ class StoryService
public static function delLatest($pid) public static function delLatest($pid)
{ {
return Cache::forget(self::STORY_KEY . 'latest:pid-' . $pid); Cache::forget(self::STORY_KEY . 'latest:pid-' . $pid);
return Cache::forget('pf:stories:recent-self:' . $pid);
} }
public static function addSeen($pid, $sid) public static function addSeen($pid, $sid)