@@ -37,28 +37,53 @@ public function recent(Request $request)
37
37
$ pid = $ request ->user ()->profile_id ;
38
38
39
39
if (config ('database.default ' ) == 'pgsql ' ) {
40
- $ s = Story::select ('stories.* ' , 'followers.following_id ' )
41
- ->leftJoin ('followers ' , 'followers.following_id ' , 'stories.profile_id ' )
42
- ->where ('followers.profile_id ' , $ pid )
43
- ->where ('stories.active ' , true )
40
+ $ s = Cache::remember ('pf:stories:recent-by-id: ' . $ pid , 900 , function () use ($ pid ) {
41
+ return Story::select ('stories.* ' , 'followers.following_id ' )
42
+ ->leftJoin ('followers ' , 'followers.following_id ' , 'stories.profile_id ' )
43
+ ->where ('followers.profile_id ' , $ pid )
44
+ ->where ('stories.active ' , true )
45
+ ->get ()
46
+ ->map (function ($ s ) {
47
+ $ r = new \StdClass ;
48
+ $ r ->id = $ s ->id ;
49
+ $ r ->profile_id = $ s ->profile_id ;
50
+ $ r ->type = $ s ->type ;
51
+ $ r ->path = $ s ->path ;
52
+ return $ r ;
53
+ })
54
+ ->unique ('profile_id ' );
55
+ });
56
+
57
+ } else {
58
+ $ s = Cache::remember ('pf:stories:recent-by-id: ' . $ pid , 900 , function () use ($ pid ) {
59
+ return Story::select ('stories.* ' , 'followers.following_id ' )
60
+ ->leftJoin ('followers ' , 'followers.following_id ' , 'stories.profile_id ' )
61
+ ->where ('followers.profile_id ' , $ pid )
62
+ ->where ('stories.active ' , true )
63
+ ->groupBy ('followers.following_id ' )
64
+ ->orderByDesc ('id ' )
65
+ ->get ();
66
+ });
67
+ }
68
+
69
+ $ self = Cache::remember ('pf:stories:recent-self: ' . $ pid , 21600 , function () use ($ pid ) {
70
+ return Story::whereProfileId ($ pid )
71
+ ->whereActive (true )
72
+ ->orderByDesc ('id ' )
73
+ ->limit (1 )
44
74
->get ()
45
- ->map (function ($ s ) {
75
+ ->map (function ($ s ) use ( $ pid ) {
46
76
$ r = new \StdClass ;
47
77
$ r ->id = $ s ->id ;
48
- $ r ->profile_id = $ s -> profile_id ;
78
+ $ r ->profile_id = $ pid ;
49
79
$ r ->type = $ s ->type ;
50
80
$ r ->path = $ s ->path ;
51
81
return $ r ;
52
- })
53
- ->unique ('profile_id ' );
54
- } else {
55
- $ s = Story::select ('stories.* ' , 'followers.following_id ' )
56
- ->leftJoin ('followers ' , 'followers.following_id ' , 'stories.profile_id ' )
57
- ->where ('followers.profile_id ' , $ pid )
58
- ->where ('stories.active ' , true )
59
- ->groupBy ('followers.following_id ' )
60
- ->orderByDesc ('id ' )
61
- ->get ();
82
+ });
83
+ });
84
+
85
+ if ($ self ->count ()) {
86
+ $ s ->prepend ($ self ->first ());
62
87
}
63
88
64
89
$ res = $ s ->map (function ($ s ) use ($ pid ) {
@@ -93,7 +118,7 @@ public function profile(Request $request, $id)
93
118
$ profile = Profile::findOrFail ($ id );
94
119
95
120
if ($ authed != $ profile ->id && !FollowerService::follows ($ authed , $ profile ->id )) {
96
- return [] ;
121
+ return abort ([], 403 ) ;
97
122
}
98
123
99
124
$ stories = Story::whereProfileId ($ profile ->id )
@@ -164,7 +189,6 @@ public function viewed(Request $request)
164
189
$ publicOnly = (bool ) $ profile ->followedBy ($ authed );
165
190
abort_if (!$ publicOnly , 403 );
166
191
167
-
168
192
$ v = StoryView::firstOrCreate ([
169
193
'story_id ' => $ id ,
170
194
'profile_id ' => $ authed ->id
0 commit comments