v3: use query object for include logic to avoid n+1 queries
This commit is contained in:
parent
ad7ff86aa7
commit
c3e96c4a55
|
@ -26,9 +26,10 @@ module Travis::API::V3
|
||||||
|
|
||||||
attr_reader :params, :main_type
|
attr_reader :params, :main_type
|
||||||
|
|
||||||
def initialize(params, main_type)
|
def initialize(params, main_type, includes = nil)
|
||||||
@params = params
|
@params = params
|
||||||
@main_type = main_type.to_s
|
@main_type = main_type.to_s
|
||||||
|
@includes = includes
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_async(identifier, *args)
|
def perform_async(identifier, *args)
|
||||||
|
|
|
@ -57,6 +57,10 @@ module Travis::API::V3
|
||||||
include.include?(field)
|
include.include?(field)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def query(type)
|
||||||
|
Queries[type].new({}, type, includes: include)
|
||||||
|
end
|
||||||
|
|
||||||
def render(representation)
|
def render(representation)
|
||||||
if included.include? model
|
if included.include? model
|
||||||
return REDUNDANT unless href
|
return REDUNDANT unless href
|
||||||
|
|
|
@ -17,7 +17,8 @@ module Travis::API::V3
|
||||||
end
|
end
|
||||||
|
|
||||||
def repositories
|
def repositories
|
||||||
access_control.visible_repositories(@model.repositories)
|
repositories = query(:repositories).for_owner(@model)
|
||||||
|
access_control.visible_repositories(repositories)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user