From 3c431244463f2efbd178e95dd7fb341d15bd3a7b Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Sun, 14 Feb 2021 19:45:58 +0000 Subject: [PATCH] Streamline calls to `orderBy` --- app/Console/Commands/RebuildTags.php | 2 +- app/Console/Commands/SyncPoniverseAccounts.php | 2 +- app/Http/Controllers/Api/Web/AlbumsController.php | 4 ++-- app/Http/Controllers/Api/Web/AnnouncementsController.php | 6 +++--- app/Http/Controllers/Api/Web/ArtistsController.php | 6 +++--- app/Http/Controllers/Api/Web/CommentsController.php | 2 +- app/Http/Controllers/Api/Web/DashboardController.php | 2 +- app/Http/Controllers/Api/Web/GenresController.php | 2 +- app/Http/Controllers/Api/Web/PlaylistsController.php | 4 ++-- app/Http/Controllers/Api/Web/ShowSongsController.php | 2 +- app/Http/Controllers/Api/Web/TracksController.php | 2 +- app/Models/Album.php | 4 ++-- app/Models/Notification.php | 2 +- app/Models/Playlist.php | 4 ++-- app/Models/Track.php | 2 +- app/Models/User.php | 2 +- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/Console/Commands/RebuildTags.php b/app/Console/Commands/RebuildTags.php index 8355aaab..f604ba9c 100644 --- a/app/Console/Commands/RebuildTags.php +++ b/app/Console/Commands/RebuildTags.php @@ -59,7 +59,7 @@ class RebuildTags extends Command $track = Track::findOrFail($this->argument('trackId')); $tracks = [$track]; } else { - $tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get(); + $tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id')->get(); } $numberOfTracks = count($tracks); diff --git a/app/Console/Commands/SyncPoniverseAccounts.php b/app/Console/Commands/SyncPoniverseAccounts.php index 6a28402f..2b25c9b1 100644 --- a/app/Console/Commands/SyncPoniverseAccounts.php +++ b/app/Console/Commands/SyncPoniverseAccounts.php @@ -71,7 +71,7 @@ class SyncPoniverseAccounts extends Command %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%'); $usersToUpdate - ->orderBy('id', 'ASC') + ->orderBy('id') ->chunk(100, function ($users) use ($progress) { /** @var User $user */ foreach ($users as $user) { diff --git a/app/Http/Controllers/Api/Web/AlbumsController.php b/app/Http/Controllers/Api/Web/AlbumsController.php index 7c1e37bc..0d213233 100644 --- a/app/Http/Controllers/Api/Web/AlbumsController.php +++ b/app/Http/Controllers/Api/Web/AlbumsController.php @@ -134,7 +134,7 @@ class AlbumsController extends ApiControllerBase $perPage = 40; $query - ->orderBy('title', 'asc') + ->orderBy('title') ->skip(($page - 1) * $perPage) ->take($perPage); $albums = []; @@ -156,7 +156,7 @@ class AlbumsController extends ApiControllerBase $query = Album::summary() ->with('cover', 'user.avatar') ->where('user_id', $user->id) - ->orderBy('created_at', 'desc')->get(); + ->orderByDesc('created_at')->get(); $albums = []; foreach ($query as $album) { diff --git a/app/Http/Controllers/Api/Web/AnnouncementsController.php b/app/Http/Controllers/Api/Web/AnnouncementsController.php index a80daf53..8393ebcb 100644 --- a/app/Http/Controllers/Api/Web/AnnouncementsController.php +++ b/app/Http/Controllers/Api/Web/AnnouncementsController.php @@ -37,7 +37,7 @@ class AnnouncementsController extends Controller ->whereNotNull('end_time') ->where('start_time', '<', $currentDate) ->where('end_time', '>', $currentDate) - ->orderBy('start_time', 'desc'); + ->orderByDesc('start_time'); $announcement = $query->first(); @@ -51,7 +51,7 @@ class AnnouncementsController extends Controller { $this->authorize('access-admin-area'); - $announcements = Announcement::orderBy('start_time', 'desc') + $announcements = Announcement::orderByDesc('start_time') ->get(); return response()->json([ @@ -64,7 +64,7 @@ class AnnouncementsController extends Controller $this->authorize('access-admin-area'); $query = Announcement::where('id', '=', $genreId) - ->orderBy('start_time', 'desc'); + ->orderByDesc('start_time'); $announcement = $query->first(); diff --git a/app/Http/Controllers/Api/Web/ArtistsController.php b/app/Http/Controllers/Api/Web/ArtistsController.php index 1806afe7..17b68163 100644 --- a/app/Http/Controllers/Api/Web/ArtistsController.php +++ b/app/Http/Controllers/Api/Web/ArtistsController.php @@ -112,7 +112,7 @@ class ArtistsController extends ApiControllerBase $query = Album::summary() ->with('user') - ->orderBy('created_at', 'desc') + ->orderByDesc('created_at') ->where('track_count', '>', 0) ->whereUserId($user->id); @@ -148,7 +148,7 @@ class ArtistsController extends ApiControllerBase ->userDetails() ->whereUserId($user->id) ->whereNotNull('published_at') - ->orderBy('created_at', 'desc') + ->orderByDesc('created_at') ->take(20); $latestTracks = []; @@ -218,7 +218,7 @@ class ArtistsController extends ApiControllerBase // The query results are ordered after they're counted // due to Postgres's behaviour when combining those two operations. - $query->orderBy('display_name', 'asc'); + $query->orderBy('display_name'); $perPage = 40; $query->skip(($page - 1) * $perPage)->take($perPage); $users = []; diff --git a/app/Http/Controllers/Api/Web/CommentsController.php b/app/Http/Controllers/Api/Web/CommentsController.php index 3dd6ea55..205a81cb 100644 --- a/app/Http/Controllers/Api/Web/CommentsController.php +++ b/app/Http/Controllers/Api/Web/CommentsController.php @@ -56,7 +56,7 @@ class CommentsController extends ApiControllerBase } } - $query = Comment::where($column, '=', $id)->orderBy('created_at', 'desc')->with('user'); + $query = Comment::where($column, '=', $id)->orderByDesc('created_at')->with('user'); $comments = []; foreach ($query->get() as $comment) { diff --git a/app/Http/Controllers/Api/Web/DashboardController.php b/app/Http/Controllers/Api/Web/DashboardController.php index b595ed2a..8bd6342d 100644 --- a/app/Http/Controllers/Api/Web/DashboardController.php +++ b/app/Http/Controllers/Api/Web/DashboardController.php @@ -36,7 +36,7 @@ class DashboardController extends ApiControllerBase ->userDetails() ->explicitFilter() ->published() - ->orderBy('published_at', 'desc') + ->orderByDesc('published_at') ->take(30); $recentQuery->whereHas('user', function ($q) { diff --git a/app/Http/Controllers/Api/Web/GenresController.php b/app/Http/Controllers/Api/Web/GenresController.php index 52f28787..12815f26 100644 --- a/app/Http/Controllers/Api/Web/GenresController.php +++ b/app/Http/Controllers/Api/Web/GenresController.php @@ -37,7 +37,7 @@ class GenresController extends ApiControllerBase $genres = Genre::with(['trackCountRelation' => function ($query) { $query->withTrashed(); }]) - ->orderBy('name', 'asc') + ->orderBy('name') ->get(); return response()->json([ diff --git a/app/Http/Controllers/Api/Web/PlaylistsController.php b/app/Http/Controllers/Api/Web/PlaylistsController.php index b3b74574..b7be6895 100644 --- a/app/Http/Controllers/Api/Web/PlaylistsController.php +++ b/app/Http/Controllers/Api/Web/PlaylistsController.php @@ -167,7 +167,7 @@ class PlaylistsController extends ApiControllerBase $join->on('playlist_id', '=', 'playlists.id'); }) ->where('pinned_playlists.user_id', '=', Auth::user()->id) - ->orderBy('title', 'asc') + ->orderBy('title') ->select('playlists.*') ->get(); @@ -187,7 +187,7 @@ class PlaylistsController extends ApiControllerBase $query = Playlist::summary() ->with('pins', 'tracks', 'tracks.cover') ->where('user_id', $user->id) - ->orderBy('title', 'asc') + ->orderBy('title') ->get(); $playlists = []; diff --git a/app/Http/Controllers/Api/Web/ShowSongsController.php b/app/Http/Controllers/Api/Web/ShowSongsController.php index 160c244c..434cff46 100644 --- a/app/Http/Controllers/Api/Web/ShowSongsController.php +++ b/app/Http/Controllers/Api/Web/ShowSongsController.php @@ -37,7 +37,7 @@ class ShowSongsController extends ApiControllerBase $songs = ShowSong::with(['trackCountRelation' => function ($query) { $query->withTrashed(); }]) - ->orderBy('title', 'asc') + ->orderBy('title') ->select('id', 'title', 'slug') ->get(); diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index 8f09e58e..0e020e68 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -263,7 +263,7 @@ class TracksController extends ApiControllerBase public function getOwned(User $user) { - $query = Track::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc'); + $query = Track::summary()->where('user_id', $user->id)->orderByDesc('created_at'); $tracks = []; foreach ($query->get() as $track) { diff --git a/app/Models/Album.php b/app/Models/Album.php index 1a4a7a15..265a6c32 100644 --- a/app/Models/Album.php +++ b/app/Models/Album.php @@ -150,7 +150,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function tracks() { - return $this->hasMany(Track::class)->orderBy('track_number', 'asc'); + return $this->hasMany(Track::class)->orderBy('track_number'); } public function trackFiles() @@ -162,7 +162,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable public function comments():HasMany { - return $this->hasMany(Comment::class)->orderBy('created_at', 'desc'); + return $this->hasMany(Comment::class)->orderByDesc('created_at'); } public function activities():MorphMany diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 24b950ff..24cff7d9 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -84,7 +84,7 @@ class Notification extends Model ->where('notifications.user_id', $user->id) ->whereNull('activities.deleted_at') ->select('*', 'notifications.id as id') - ->orderBy('activities.created_at', 'DESC'); + ->orderByDesc('activities.created_at'); return $result; } diff --git a/app/Models/Playlist.php b/app/Models/Playlist.php index d57be12a..bb2087b3 100644 --- a/app/Models/Playlist.php +++ b/app/Models/Playlist.php @@ -244,7 +244,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable ->withTimestamps(); if ($ordered) { - $query = $query->orderBy('position', 'asc'); + $query = $query->orderBy('position'); } return $query; @@ -269,7 +269,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable public function comments():HasMany { - return $this->hasMany(Comment::class)->orderBy('created_at', 'desc'); + return $this->hasMany(Comment::class)->orderByDesc('created_at'); } public function pins() diff --git a/app/Models/Track.php b/app/Models/Track.php index 47ff0522..592a13e5 100644 --- a/app/Models/Track.php +++ b/app/Models/Track.php @@ -706,7 +706,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable public function comments():HasMany { - return $this->hasMany(Comment::class)->orderBy('created_at', 'desc'); + return $this->hasMany(Comment::class)->orderByDesc('created_at'); } public function favourites():HasMany diff --git a/app/Models/User.php b/app/Models/User.php index 091d7ee3..931d6a57 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -312,7 +312,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon public function comments():HasMany { - return $this->hasMany(Comment::class, 'profile_id')->orderBy('created_at', 'desc'); + return $this->hasMany(Comment::class, 'profile_id')->orderByDesc('created_at'); } public function tracks()