Skip to content
Snippets Groups Projects
Commit e53169c9 authored by Douwe Maan's avatar Douwe Maan
Browse files

Resolve N+1 query issue with discussions

parent 1ac12698
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -43,7 +43,12 @@ module Noteable
end
 
def resolvable_discussions
@resolvable_discussions ||= discussion_notes.resolvable.discussions(self)
@resolvable_discussions ||=
if defined?(@discussions)
@discussions.select(&:resolvable?)
else
discussion_notes.resolvable.discussions(self)
end
end
 
def discussions_resolvable?
Loading
Loading
Loading
Loading
@@ -21,7 +21,8 @@ class Discussion
end
 
def self.build_collection(notes, context_noteable = nil)
notes.group_by { |n| n.discussion_id(context_noteable) }.values.map { |notes| build(notes, context_noteable) }
grouped_notes = notes.includes(:noteable).group_by { |n| n.discussion_id(context_noteable) }
grouped_notes.values.map { |notes| build(notes, context_noteable) }
end
 
# Returns an alphanumeric discussion ID based on `build_discussion_id`
Loading
Loading
---
title: Resolve N+1 query issue with discussions
merge_request:
author:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment