2
나는 열망하는로드를 통해 가능한 한 DB 호출을 거의하지 않겠다는 몇 가지 시나리오를 가지고 있지만 잘 수행하지 못했습니다.mongoid와 함께 RABL을 사용할 때 DB 호출 줄이기
아래의 두 가지 시나리오를 감안할 때 가능한 한 적은 수의 호출로 RABL을 어떻게 변경할 수 있습니까?
개체 모델 :
Posts
-> belongs_to user
-> has_many: Comments
-> Comment belongs_to user
-> has_many: Tags
-> Tag belongs_to user
RABL
node(:comments) do |p|
p.filtered_comments(@user)
end
child :tags do
attribute :text
child :users do
attribute :nickname
end
end
CONTROLLER 쿼리를
Post.includes(user, comments, tags)...
POST를 (이 두 가지 많은 개별 호출을 수행 할 DB의 원인이됩니다). RB
def filtered_comments
comments = self.comments.where(:blocked=>false).all
json = Rabl::Renderer.json(comments, 'comments/list', view_path: 'app/views')
JSON.parse(json).map do |c|
c['comment']
end
end
얼마나 많은 검색어가 발생했는지에 대한 로그가 있습니까? –
사용자가 'filtered_comments' 메소드를 받아들이지 않으면 어떻게 전달합니까? –