Use scopes for better query performance

This commit is contained in:
Alberto Miedes Garcés
2017-06-01 20:04:51 +02:00
parent 18db68a430
commit 9ec8b166d7
11 changed files with 14 additions and 24 deletions

View File

@@ -1,12 +0,0 @@
module PublicForApi
extend ActiveSupport::Concern
class_methods do
def public_for_api
all
end
end
end
ActiveRecord::Base.send(:include, PublicForApi)

View File

@@ -50,7 +50,7 @@ module GraphQL
when :multiple_association
field_type = field_type.first
connection(field_name, -> { created_types[field_type].connection_type }, max_page_size: 50, complexity: 1000) do
resolve -> (object, arguments, context) { field_type.public_for_api & object.send(field_name) }
resolve -> (object, arguments, context) { object.send(field_name).public_for_api }
end
end
end