Skip to content

Commit

Permalink
refactor: don't use unnecessary orderByRaw
Browse files Browse the repository at this point in the history
Null values are always ordered last anyways. Additionally, count(*) returns 0, not null. Also fixes issue on mariadb with value being a reserved keyword.
  • Loading branch information
Roardom committed Feb 11, 2025
1 parent e45231b commit 5e8f54f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/Http/Livewire/TopUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ final public function commenters(): \Illuminate\Support\Collection
->where('user_id', '!=', User::SYSTEM_USER_ID)
->where('anon', '=', false)
->groupBy('user_id')
->orderByRaw('COALESCE(value, 0) DESC')
->orderByDesc('value')
->take(8)
->get();
}
Expand All @@ -154,7 +154,7 @@ final public function posters(): \Illuminate\Support\Collection
->select(DB::raw('user_id, COUNT(user_id) as value'))
->where('user_id', '!=', User::SYSTEM_USER_ID)
->groupBy('user_id')
->orderByRaw('COALESCE(value, 0) DESC')
->orderByDesc('value')
->take(8)
->get();
}
Expand All @@ -169,7 +169,7 @@ final public function thankers(): \Illuminate\Support\Collection
->select(DB::raw('user_id, COUNT(user_id) as value'))
->where('user_id', '!=', User::SYSTEM_USER_ID)
->groupBy('user_id')
->orderByRaw('COALESCE(value, 0) DESC')
->orderByDesc('value')
->take(8)
->get();
}
Expand Down

0 comments on commit 5e8f54f

Please sign in to comment.