From 47f5bd64cbb1f9e5db07c87fcc90ae9ccfa691c0 Mon Sep 17 00:00:00 2001 From: nelsonlaquet Date: Sun, 1 Sep 2013 05:57:17 -0500 Subject: [PATCH] fixed script --- app/commands/RefreshCache.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/commands/RefreshCache.php b/app/commands/RefreshCache.php index 40027d17..34a48f5d 100644 --- a/app/commands/RefreshCache.php +++ b/app/commands/RefreshCache.php @@ -16,9 +16,21 @@ class RefreshCache extends Command { DB::connection()->disableQueryLog(); DB::table('tracks')->update(['comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.track_id = tracks.id AND deleted_at IS NULL)')]); - DB::table('albums')->update(['comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.album_id = albums.id AND deleted_at IS NULL)')]); - DB::table('playlists')->update(['comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.playlist_id = playlists.id AND deleted_at IS NULL)')]); - DB::table('users')->update(['comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.profile_id = users.id AND deleted_at IS NULL)')]); + + DB::table('albums')->update([ + 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.album_id = albums.id AND deleted_at IS NULL)'), + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE album_id = albums.id)') + ]); + + DB::table('playlists')->update([ + 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.playlist_id = playlists.id AND deleted_at IS NULL)'), + 'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = playlists.id)') + ]); + + DB::table('users')->update([ + 'comment_count' => DB::raw('(SELECT COUNT(id) FROM comments WHERE comments.profile_id = users.id AND deleted_at IS NULL)'), + 'track_count' => DB::raw('(SELECT COUNT(id) FROM tracks WHERE deleted_at IS NULL AND published_at IS NOT NULL AND user_id = users.id)') + ]); $users = DB::table('users')->get(); $cacheItems = [];