diff --git a/app/logical/post_sets/artist.rb b/app/logical/post_sets/artist.rb index 1fb619498..96e2ba6a2 100644 --- a/app/logical/post_sets/artist.rb +++ b/app/logical/post_sets/artist.rb @@ -8,7 +8,11 @@ module PostSets end def posts - ::Post.tag_match(@artist.name).limit(10) + @posts ||= begin + query = ::Post.tag_match(@artist.name).limit(10) + query.each # hack to force rails to eager load + query + end rescue ::Post::SearchError ::Post.where("false") end diff --git a/app/logical/post_sets/favorite.rb b/app/logical/post_sets/favorite.rb index 9d1c9e0fe..3f2789db1 100644 --- a/app/logical/post_sets/favorite.rb +++ b/app/logical/post_sets/favorite.rb @@ -25,7 +25,7 @@ module PostSets end def posts - favorites.includes(:post).map(&:post).compact + @posts ||= favorites.includes(:post).map(&:post).compact end def presenter diff --git a/app/logical/post_sets/popular.rb b/app/logical/post_sets/popular.rb index c55d17bf6..f5f2df4f8 100644 --- a/app/logical/post_sets/popular.rb +++ b/app/logical/post_sets/popular.rb @@ -8,7 +8,11 @@ module PostSets end def posts - ::Post.where("created_at between ? and ?", min_date.beginning_of_day, max_date.end_of_day).order("score desc").limit(limit) + @posts ||= begin + query = ::Post.where("created_at between ? and ?", min_date.beginning_of_day, max_date.end_of_day).order("score desc").limit(limit) + query.each # hack to force rails to eager load + query + end end def limit