Skip to content

Commit b583ae8

Browse files
authored
⚡️ improve query (#3292)
1 parent ad5e4e2 commit b583ae8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/Http/Controllers/StatusController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public static function getActiveStatuses(): ?Collection {
7777
'checkin.trip.polyline',
7878
'tags',
7979
])
80-
->whereHas('checkin', function($query) {
81-
$query->where('departure', '<', now())
82-
->where('arrival', '>', now());
83-
})
80+
->join('train_checkins', 'statuses.id', '=', 'train_checkins.status_id')
81+
->where('train_checkins.departure', '<', now())
82+
->where('train_checkins.arrival', '>', now())
83+
->select('statuses.*')
8484
->get()
8585
->filter(function(Status $status) {
8686
return Gate::allows('view', $status) && $status->visibility !== StatusVisibility::UNLISTED;
@@ -167,9 +167,9 @@ public static function createLike(User $user, Status $status): Like {
167167
}
168168

169169
$like = Like::updateOrCreate([
170-
'user_id' => $user->id,
171-
'status_id' => $status->id,
172-
]);
170+
'user_id' => $user->id,
171+
'status_id' => $status->id,
172+
]);
173173

174174
if (!$status->user->mutedUsers->contains('id', $user->id)) {
175175
$status->user->notify(new StatusLiked($like));

0 commit comments

Comments
 (0)