Ищете способы улучшить особенно плохую производительность, которую я получаю от своего приложения для рельсов. Вот код на странице в вопросе:Плохая производительность в Rails App
notifications_controller.rb
class NotificationsController < ApplicationController
def index
@questions = Question.all.order(:updated_at => :desc)
@users = User.all
@answers = Answer.all.order(:updated_at => :desc)
end
end
и вот соответствующий вид. Я знаю, что это уродливо, но оно работает.
<div>
<% if current_user %>
<div class="notifications-added col-md-8">
<h4 class="col-md-offset-2">Approvals & Answers</h4>
<span class="text-center">
<% current_user.questions.order(id: :desc).each do |question| %>
<% if question.approved == true %>
Your question, <%= link_to "#{question.title}", question_path(question) %>, has been <span class="notifications">approved.</span><br>
<% end %>
<% question.answers.each do |answer| %>
<%= answer.user.name %> <span class="notifications">added an answer</span> to your question, <%= link_to "#{question.title}", question_path(question) %>.<br>
<% end %>
<% end %>
</span>
</div>
<div class="notifications-voted col-md-4">
<h4 class="text-center">Votes</h4><span></span>
<% current_user.answers.order(updated_at: :desc).each do |answer| %>
<% @users.each do |user| %>
<% if user.voted_up_on? answer %>
<%= user.name %> <span class="notifications">upvoted</span> your answer to <%= link_to "#{Question.find(answer.question_id).title}", question_path(answer.question_id) %>.<br>
<% elsif user.voted_down_on? answer %>
<%= user.name %> <span class="notifications">downvoted</span> your answer to <%= link_to "#{Question.find(answer.question_id).title}", question_path(answer.question_id) %>. <br>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
</div>
Я думаю, что я просто сортирую слишком много. Страница занимает много времени, чтобы загрузить. Что такое низкие висячие плоды для улучшения моей работы? Есть предположения? Заранее спасибо.
Вы определяете две переменные '@questions, @ answers', но используются' current_user.questions' и 'current_user.answers'. почему вам нужна переменная @questions, @ answers', если вы ее не используете? –