Skip to content

Commit c427900

Browse files
committed
Update AccountService, and NotificationResource
1 parent e645f85 commit c427900

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

app/Http/Resources/NotificationResource.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function newVideoCommentReplyShare()
6161
'video_pid' => $videoPid,
6262
'video_id' => (string) $this->video_id,
6363
'video_thumbnail' => $thumb,
64-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
64+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
6565
'url' => $link,
6666
'read_at' => $this->read_at,
6767
'created_at' => $this->created_at,
@@ -84,7 +84,7 @@ protected function newVideoCommentShare()
8484
'video_id' => (string) $this->video_id,
8585
'video_thumbnail' => $thumb,
8686
'url' => $link,
87-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
87+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
8888
'read_at' => $this->read_at,
8989
'created_at' => $this->created_at,
9090
];
@@ -102,7 +102,7 @@ protected function newVideoShare()
102102
'video_pid' => $videoPid,
103103
'video_id' => (string) $this->video_id,
104104
'video_thumbnail' => $thumb,
105-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
105+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
106106
'read_at' => $this->read_at,
107107
'created_at' => $this->created_at,
108108
];
@@ -119,7 +119,7 @@ protected function newVideoDuet()
119119
return [
120120
'id' => (string) $this->id,
121121
'type' => 'video.duet',
122-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
122+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
123123
'video_pid' => $videoPid,
124124
'video_id' => (string) $this->video_id,
125125
'video_thumbnail' => $thumb,
@@ -141,7 +141,7 @@ protected function newVideoCommentReply()
141141
return [
142142
'id' => (string) $this->id,
143143
'type' => 'video.commentReply',
144-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
144+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
145145
'video_pid' => $videoPid,
146146
'video_id' => (string) $this->video_id,
147147
'video_thumbnail' => $thumb,
@@ -166,7 +166,7 @@ protected function newVideoCommentReplyLike()
166166
'video_pid' => $videoPid,
167167
'video_id' => (string) $this->video_id,
168168
'video_thumbnail' => $thumb,
169-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
169+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
170170
'url' => $link,
171171
'read_at' => $this->read_at,
172172
'created_at' => $this->created_at,
@@ -189,7 +189,7 @@ protected function newVideoCommentLike()
189189
'video_id' => (string) $this->video_id,
190190
'video_thumbnail' => $thumb,
191191
'url' => $link,
192-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
192+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
193193
'read_at' => $this->read_at,
194194
'created_at' => $this->created_at,
195195
];
@@ -207,7 +207,7 @@ protected function newVideoLike()
207207
'video_pid' => $videoPid,
208208
'video_id' => (string) $this->video_id,
209209
'video_thumbnail' => $thumb,
210-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
210+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
211211
'read_at' => $this->read_at,
212212
'created_at' => $this->created_at,
213213
];
@@ -218,7 +218,7 @@ protected function newFollower()
218218
return [
219219
'id' => (string) $this->id,
220220
'type' => 'new_follower',
221-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
221+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
222222
'read_at' => $this->read_at,
223223
'created_at' => $this->created_at,
224224
];
@@ -236,7 +236,7 @@ protected function newVideoComment()
236236
return [
237237
'id' => (string) $this->id,
238238
'type' => 'video.comment',
239-
'actor' => AccountService::compact($this->profile_id, false) ?: $this->unavailableAccount(),
239+
'actor' => AccountService::get($this->profile_id, false) ?: $this->unavailableAccount(),
240240
'video_pid' => $videoPid,
241241
'video_id' => (string) $this->video_id,
242242
'video_thumbnail' => $thumb,

app/Services/AccountService.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
use App\Http\Resources\ProfileResource;
66
use App\Models\Profile;
77
use App\Models\Video;
8-
use Cache;
98
use Illuminate\Http\Request;
9+
use Illuminate\Support\Facades\Cache;
1010

1111
class AccountService
1212
{
1313
const CACHE_KEY = 'api:s:account:';
1414

1515
const ACCOUNT_LIKES_CACHE_KEY = 'api:s:account:likes_count:';
1616

17-
public static function get($id)
17+
public static function get($id, $grace = true)
1818
{
1919
$res = Cache::remember(self::CACHE_KEY.$id, now()->addDays(7), function () use ($id) {
2020
$req = new Request;
@@ -26,7 +26,11 @@ public static function get($id)
2626
return (new ProfileResource($profile))->toArray($req);
2727
});
2828

29-
return $res ? $res : [];
29+
if($res) {
30+
return $res;
31+
}
32+
33+
return $grace ? [] : false;
3034
}
3135

3236
public static function getActorId($id)

0 commit comments

Comments
 (0)