mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-01-31 19:16:44 +01:00
Streamline calls to orderBy
This commit is contained in:
parent
3f85a1ca06
commit
3c43124446
16 changed files with 24 additions and 24 deletions
|
@ -59,7 +59,7 @@ class RebuildTags extends Command
|
||||||
$track = Track::findOrFail($this->argument('trackId'));
|
$track = Track::findOrFail($this->argument('trackId'));
|
||||||
$tracks = [$track];
|
$tracks = [$track];
|
||||||
} else {
|
} else {
|
||||||
$tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id', 'asc')->get();
|
$tracks = Track::whereNotNull('published_at')->withTrashed()->orderBy('id')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
$numberOfTracks = count($tracks);
|
$numberOfTracks = count($tracks);
|
||||||
|
|
|
@ -71,7 +71,7 @@ class SyncPoniverseAccounts extends Command
|
||||||
%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%');
|
%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%');
|
||||||
|
|
||||||
$usersToUpdate
|
$usersToUpdate
|
||||||
->orderBy('id', 'ASC')
|
->orderBy('id')
|
||||||
->chunk(100, function ($users) use ($progress) {
|
->chunk(100, function ($users) use ($progress) {
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ class AlbumsController extends ApiControllerBase
|
||||||
$perPage = 40;
|
$perPage = 40;
|
||||||
|
|
||||||
$query
|
$query
|
||||||
->orderBy('title', 'asc')
|
->orderBy('title')
|
||||||
->skip(($page - 1) * $perPage)
|
->skip(($page - 1) * $perPage)
|
||||||
->take($perPage);
|
->take($perPage);
|
||||||
$albums = [];
|
$albums = [];
|
||||||
|
@ -156,7 +156,7 @@ class AlbumsController extends ApiControllerBase
|
||||||
$query = Album::summary()
|
$query = Album::summary()
|
||||||
->with('cover', 'user.avatar')
|
->with('cover', 'user.avatar')
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->orderBy('created_at', 'desc')->get();
|
->orderByDesc('created_at')->get();
|
||||||
$albums = [];
|
$albums = [];
|
||||||
|
|
||||||
foreach ($query as $album) {
|
foreach ($query as $album) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ class AnnouncementsController extends Controller
|
||||||
->whereNotNull('end_time')
|
->whereNotNull('end_time')
|
||||||
->where('start_time', '<', $currentDate)
|
->where('start_time', '<', $currentDate)
|
||||||
->where('end_time', '>', $currentDate)
|
->where('end_time', '>', $currentDate)
|
||||||
->orderBy('start_time', 'desc');
|
->orderByDesc('start_time');
|
||||||
|
|
||||||
$announcement = $query->first();
|
$announcement = $query->first();
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class AnnouncementsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('access-admin-area');
|
$this->authorize('access-admin-area');
|
||||||
|
|
||||||
$announcements = Announcement::orderBy('start_time', 'desc')
|
$announcements = Announcement::orderByDesc('start_time')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
@ -64,7 +64,7 @@ class AnnouncementsController extends Controller
|
||||||
$this->authorize('access-admin-area');
|
$this->authorize('access-admin-area');
|
||||||
|
|
||||||
$query = Announcement::where('id', '=', $genreId)
|
$query = Announcement::where('id', '=', $genreId)
|
||||||
->orderBy('start_time', 'desc');
|
->orderByDesc('start_time');
|
||||||
|
|
||||||
$announcement = $query->first();
|
$announcement = $query->first();
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ class ArtistsController extends ApiControllerBase
|
||||||
|
|
||||||
$query = Album::summary()
|
$query = Album::summary()
|
||||||
->with('user')
|
->with('user')
|
||||||
->orderBy('created_at', 'desc')
|
->orderByDesc('created_at')
|
||||||
->where('track_count', '>', 0)
|
->where('track_count', '>', 0)
|
||||||
->whereUserId($user->id);
|
->whereUserId($user->id);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class ArtistsController extends ApiControllerBase
|
||||||
->userDetails()
|
->userDetails()
|
||||||
->whereUserId($user->id)
|
->whereUserId($user->id)
|
||||||
->whereNotNull('published_at')
|
->whereNotNull('published_at')
|
||||||
->orderBy('created_at', 'desc')
|
->orderByDesc('created_at')
|
||||||
->take(20);
|
->take(20);
|
||||||
|
|
||||||
$latestTracks = [];
|
$latestTracks = [];
|
||||||
|
@ -218,7 +218,7 @@ class ArtistsController extends ApiControllerBase
|
||||||
|
|
||||||
// The query results are ordered after they're counted
|
// The query results are ordered after they're counted
|
||||||
// due to Postgres's behaviour when combining those two operations.
|
// due to Postgres's behaviour when combining those two operations.
|
||||||
$query->orderBy('display_name', 'asc');
|
$query->orderBy('display_name');
|
||||||
$perPage = 40;
|
$perPage = 40;
|
||||||
$query->skip(($page - 1) * $perPage)->take($perPage);
|
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||||
$users = [];
|
$users = [];
|
||||||
|
|
|
@ -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 = [];
|
$comments = [];
|
||||||
|
|
||||||
foreach ($query->get() as $comment) {
|
foreach ($query->get() as $comment) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DashboardController extends ApiControllerBase
|
||||||
->userDetails()
|
->userDetails()
|
||||||
->explicitFilter()
|
->explicitFilter()
|
||||||
->published()
|
->published()
|
||||||
->orderBy('published_at', 'desc')
|
->orderByDesc('published_at')
|
||||||
->take(30);
|
->take(30);
|
||||||
|
|
||||||
$recentQuery->whereHas('user', function ($q) {
|
$recentQuery->whereHas('user', function ($q) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ class GenresController extends ApiControllerBase
|
||||||
$genres = Genre::with(['trackCountRelation' => function ($query) {
|
$genres = Genre::with(['trackCountRelation' => function ($query) {
|
||||||
$query->withTrashed();
|
$query->withTrashed();
|
||||||
}])
|
}])
|
||||||
->orderBy('name', 'asc')
|
->orderBy('name')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
|
@ -167,7 +167,7 @@ class PlaylistsController extends ApiControllerBase
|
||||||
$join->on('playlist_id', '=', 'playlists.id');
|
$join->on('playlist_id', '=', 'playlists.id');
|
||||||
})
|
})
|
||||||
->where('pinned_playlists.user_id', '=', Auth::user()->id)
|
->where('pinned_playlists.user_id', '=', Auth::user()->id)
|
||||||
->orderBy('title', 'asc')
|
->orderBy('title')
|
||||||
->select('playlists.*')
|
->select('playlists.*')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ class PlaylistsController extends ApiControllerBase
|
||||||
$query = Playlist::summary()
|
$query = Playlist::summary()
|
||||||
->with('pins', 'tracks', 'tracks.cover')
|
->with('pins', 'tracks', 'tracks.cover')
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->orderBy('title', 'asc')
|
->orderBy('title')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$playlists = [];
|
$playlists = [];
|
||||||
|
|
|
@ -37,7 +37,7 @@ class ShowSongsController extends ApiControllerBase
|
||||||
$songs = ShowSong::with(['trackCountRelation' => function ($query) {
|
$songs = ShowSong::with(['trackCountRelation' => function ($query) {
|
||||||
$query->withTrashed();
|
$query->withTrashed();
|
||||||
}])
|
}])
|
||||||
->orderBy('title', 'asc')
|
->orderBy('title')
|
||||||
->select('id', 'title', 'slug')
|
->select('id', 'title', 'slug')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
|
@ -263,7 +263,7 @@ class TracksController extends ApiControllerBase
|
||||||
|
|
||||||
public function getOwned(User $user)
|
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 = [];
|
$tracks = [];
|
||||||
foreach ($query->get() as $track) {
|
foreach ($query->get() as $track) {
|
||||||
|
|
|
@ -150,7 +150,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable
|
||||||
|
|
||||||
public function tracks()
|
public function tracks()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Track::class)->orderBy('track_number', 'asc');
|
return $this->hasMany(Track::class)->orderBy('track_number');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trackFiles()
|
public function trackFiles()
|
||||||
|
@ -162,7 +162,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable
|
||||||
|
|
||||||
public function comments():HasMany
|
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
|
public function activities():MorphMany
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Notification extends Model
|
||||||
->where('notifications.user_id', $user->id)
|
->where('notifications.user_id', $user->id)
|
||||||
->whereNull('activities.deleted_at')
|
->whereNull('activities.deleted_at')
|
||||||
->select('*', 'notifications.id as id')
|
->select('*', 'notifications.id as id')
|
||||||
->orderBy('activities.created_at', 'DESC');
|
->orderByDesc('activities.created_at');
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable
|
||||||
->withTimestamps();
|
->withTimestamps();
|
||||||
|
|
||||||
if ($ordered) {
|
if ($ordered) {
|
||||||
$query = $query->orderBy('position', 'asc');
|
$query = $query->orderBy('position');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
@ -269,7 +269,7 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable
|
||||||
|
|
||||||
public function comments():HasMany
|
public function comments():HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Comment::class)->orderBy('created_at', 'desc');
|
return $this->hasMany(Comment::class)->orderByDesc('created_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pins()
|
public function pins()
|
||||||
|
|
|
@ -706,7 +706,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable
|
||||||
|
|
||||||
public function comments():HasMany
|
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
|
public function favourites():HasMany
|
||||||
|
|
|
@ -312,7 +312,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
|
|
||||||
public function comments():HasMany
|
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()
|
public function tracks()
|
||||||
|
|
Loading…
Reference in a new issue