diff --git a/app/controllers/Api/Web/DashboardController.php b/app/controllers/Api/Web/DashboardController.php index 343b2ef6..5fe6ee1e 100644 --- a/app/controllers/Api/Web/DashboardController.php +++ b/app/controllers/Api/Web/DashboardController.php @@ -17,6 +17,7 @@ public function getIndex() { $recentQuery = Track::summary() ->with(['genre', 'user', 'cover', 'user.avatar']) + ->whereIsLatest(true) ->userDetails() ->explicitFilter() ->published() diff --git a/app/database/migrations/2013_09_10_014644_create_latest_column.php b/app/database/migrations/2013_09_10_014644_create_latest_column.php new file mode 100644 index 00000000..38b8e6c7 --- /dev/null +++ b/app/database/migrations/2013_09_10_014644_create_latest_column.php @@ -0,0 +1,37 @@ +boolean('is_latest')->notNullable()->indexed(); + }); + + DB::update(' + UPDATE + tracks + SET + is_latest = true + WHERE + ( + SELECT + t2.id + FROM + (SELECT id, user_id FROM tracks WHERE published_at IS NOT NULL AND deleted_at IS NULL) AS t2 + WHERE + t2.user_id = tracks.user_id + ORDER BY + created_at DESC + LIMIT 1 + ) = tracks.id + AND + published_at IS NOT NULL'); + } + + public function down() { + Schema::table('tracks', function($table) { + $table->dropColumn('is_latest'); + }); + } +} \ No newline at end of file diff --git a/app/models/Commands/EditTrackCommand.php b/app/models/Commands/EditTrackCommand.php index 5bf58d3a..468fba6f 100644 --- a/app/models/Commands/EditTrackCommand.php +++ b/app/models/Commands/EditTrackCommand.php @@ -101,6 +101,9 @@ if ($track->published_at == null) { $track->published_at = new \DateTime(); + + DB::table('tracks')->whereUserId($track->user_id)->update(['is_latest' => false]); + $track->is_latest = true; } if (isset($this->_input['cover_id'])) { diff --git a/app/models/Entities/Track.php b/app/models/Entities/Track.php index 2fab16aa..8485ed60 100644 --- a/app/models/Entities/Track.php +++ b/app/models/Entities/Track.php @@ -80,6 +80,9 @@ return $results; }); + if (!count($trackIds)) + return []; + $tracks = Track::summary() ->userDetails() ->explicitFilter() diff --git a/bootstrap/compiled.php b/bootstrap/compiled.php index bdd50c2f..cb73d68f 100644 --- a/bootstrap/compiled.php +++ b/bootstrap/compiled.php @@ -7249,7 +7249,7 @@ use Monolog\Formatter\LineFormatter; abstract class AbstractHandler implements HandlerInterface { protected $level = Logger::DEBUG; - protected $bubble = false; + protected $bubble = true; protected $formatter; protected $processors = array(); public function __construct($level = Logger::DEBUG, $bubble = true) diff --git a/public/templates/account/track.html b/public/templates/account/track.html index 28c6dd70..e76cca88 100644 --- a/public/templates/account/track.html +++ b/public/templates/account/track.html @@ -49,7 +49,7 @@