我应该帮帮忙吗? 或者这会变慢吗?

在这种情况下哪种模式会更快?
显然,带帮手的Pattern1看起来更复杂,看起来很干净。
但是每次调用user_link方法时它都会发送SQL。
在一页加载时,它最多可调用100次。

哪种方式对基准性能更好?

样式1。 有了帮手

application_helper

def user_link(username) link_to User.find_by_username(username).user_profile.nickname, show_user_path(username) end 

视图

    

模式2。 没有帮手。 只是查看

    

尝试

 # Topics model #via scope scope :get_topic_list, lambda do order("updated_at DESC").joins(:comment_threads => :user).limit(100) end #via method def self.get_topic_list Topic.order("updated_at DESC").joins(:comment_threads => :user).limit(100) end # in your controller or move to model itself (recommened) @topics = Topic.get_topic_list # in you view <% @topics.each do |topic| %> <%= link_to(topic.comment_threads.order("id").last.user.nickname, show_user_path(topic.comment_threads.order("id").last.user.username) ) if topic.comment_threads.present? %> <% end %>