mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
Added a bunch of eager-loading.
This commit is contained in:
parent
fc4ae856f8
commit
27f19f9dc7
5 changed files with 37 additions and 9 deletions
|
@ -61,7 +61,10 @@ class AlbumsController extends ApiControllerBase
|
|||
'tracks.cover',
|
||||
'tracks.genre',
|
||||
'tracks.user',
|
||||
'tracks.user.avatar',
|
||||
'tracks.trackFiles',
|
||||
'user',
|
||||
'user.avatar',
|
||||
'comments',
|
||||
'comments.user'
|
||||
])
|
||||
|
@ -146,7 +149,10 @@ class AlbumsController extends ApiControllerBase
|
|||
{
|
||||
$this->authorize('get-albums', $user);
|
||||
|
||||
$query = Album::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc')->get();
|
||||
$query = Album::summary()
|
||||
->with('cover', 'user.avatar')
|
||||
->where('user_id', $user->id)
|
||||
->orderBy('created_at', 'desc')->get();
|
||||
$albums = [];
|
||||
|
||||
foreach ($query as $album) {
|
||||
|
|
|
@ -48,8 +48,13 @@ class ArtistsController extends ApiControllerBase
|
|||
'track.genre',
|
||||
'track.cover',
|
||||
'track.user',
|
||||
'track.user.avatar',
|
||||
'track.album',
|
||||
'track.album.cover',
|
||||
'track.album.user.avatar',
|
||||
'album.cover',
|
||||
'album.user',
|
||||
'album.user.avatar',
|
||||
'track' => function ($query) {
|
||||
$query->userDetails();
|
||||
},
|
||||
|
@ -84,8 +89,14 @@ class ArtistsController extends ApiControllerBase
|
|||
App::abort(404);
|
||||
}
|
||||
|
||||
$query = Track::summary()->published()->listed()->explicitFilter()->with('genre', 'cover',
|
||||
'user')->userDetails()->whereUserId($user->id)->whereNotNull('published_at');
|
||||
$query = Track::summary()
|
||||
->published()
|
||||
->listed()
|
||||
->explicitFilter()
|
||||
->with('genre', 'cover', 'user', 'user.avatar', 'album', 'album.cover')
|
||||
->userDetails()
|
||||
->whereUserId($user->id)
|
||||
->whereNotNull('published_at');
|
||||
$tracks = [];
|
||||
$singles = [];
|
||||
|
||||
|
@ -119,7 +130,7 @@ class ArtistsController extends ApiControllerBase
|
|||
->userDetails()
|
||||
->with([
|
||||
'comments' => function ($query) {
|
||||
$query->with('user');
|
||||
$query->with(['user', 'user.avatar']);
|
||||
}
|
||||
])
|
||||
->first();
|
||||
|
@ -131,7 +142,7 @@ class ArtistsController extends ApiControllerBase
|
|||
->published()
|
||||
->explicitFilter()
|
||||
->listed()
|
||||
->with('genre', 'cover', 'user')
|
||||
->with('genre', 'cover', 'user', 'album', 'album.cover')
|
||||
->userDetails()
|
||||
->whereUserId($user->id)
|
||||
->whereNotNull('published_at')
|
||||
|
|
|
@ -70,7 +70,14 @@ class PlaylistsController extends ApiControllerBase
|
|||
}
|
||||
|
||||
$query = Playlist::summary()
|
||||
->with('user', 'user.avatar', 'tracks', 'tracks.cover', 'tracks.user', 'tracks.album', 'tracks.album.user')
|
||||
->with('user',
|
||||
'user.avatar',
|
||||
'tracks',
|
||||
'tracks.cover',
|
||||
'tracks.user',
|
||||
'tracks.user.avatar',
|
||||
'tracks.album',
|
||||
'tracks.album.user')
|
||||
->userDetails()
|
||||
->orderBy('title', 'asc')
|
||||
->where('track_count', '>', 0)
|
||||
|
@ -103,6 +110,7 @@ class PlaylistsController extends ApiControllerBase
|
|||
'tracks' => function ($query) {
|
||||
$query->userDetails();
|
||||
},
|
||||
'tracks.trackFiles',
|
||||
'comments',
|
||||
'comments.user'
|
||||
])->userDetails()->find($id);
|
||||
|
|
|
@ -88,7 +88,8 @@ class Album extends Model implements Searchable, Commentable, Favouritable
|
|||
'users' => function($query) {
|
||||
$query->whereUserId(Auth::user()->id);
|
||||
}
|
||||
]);
|
||||
])
|
||||
->with('users.avatar');
|
||||
}
|
||||
|
||||
return !$query;
|
||||
|
|
|
@ -210,7 +210,8 @@ class Track extends Model implements Searchable, Commentable, Favouritable
|
|||
return self::select('tracks.id', 'title', 'user_id', 'slug', 'is_vocal', 'is_explicit', 'created_at',
|
||||
'published_at',
|
||||
'duration', 'is_downloadable', 'genre_id', 'track_type_id', 'cover_id', 'album_id', 'comment_count',
|
||||
'download_count', 'view_count', 'play_count', 'favourite_count');
|
||||
'download_count', 'view_count', 'play_count', 'favourite_count')
|
||||
->with('user', 'cover', 'album');
|
||||
}
|
||||
|
||||
public function scopeUserDetails($query)
|
||||
|
@ -561,7 +562,8 @@ class Track extends Model implements Searchable, Commentable, Favouritable
|
|||
*/
|
||||
public function getFilesize($formatName)
|
||||
{
|
||||
$trackFile = $this->trackFiles()->where('format', $formatName)->first();
|
||||
// $trackFile = $this->trackFiles()->where('format', $formatName)->first();
|
||||
$trackFile = $this->trackFiles->where('format', $formatName)->first();
|
||||
|
||||
if ($trackFile) {
|
||||
return (int) $trackFile->filesize;
|
||||
|
|
Loading…
Reference in a new issue