API v3: remove n+1 query from owner page endpoint
This commit is contained in:
parent
cc82721565
commit
59835c80f6
|
@ -37,3 +37,4 @@ module Travis
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ module Travis::API::V3
|
|||
list = list.where(private: bool(private)) unless private.nil?
|
||||
list = list.includes(:owner) if includes? 'repository.owner'.freeze
|
||||
|
||||
if includes? 'repository.last_build'.freeze
|
||||
if includes? 'repository.last_build'.freeze or includes? 'build'.freeze
|
||||
list = list.includes(:last_build)
|
||||
list = list.includes(last_build: :commit) if includes? 'build.commit'.freeze
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module Travis::API::V3
|
|||
|
||||
attr_reader :params, :main_type
|
||||
|
||||
def initialize(params, main_type, includes = nil)
|
||||
def initialize(params, main_type, includes: nil)
|
||||
@params = params
|
||||
@main_type = main_type.to_s
|
||||
@includes = includes
|
||||
|
@ -43,7 +43,7 @@ module Travis::API::V3
|
|||
|
||||
def includes?(key)
|
||||
@includes ||= @params['include'.freeze].to_s.split(?,.freeze)
|
||||
@includes.include? key
|
||||
key.include?(?.) ? @includes.include?(key) : @includes.any? { |k| k.start_with? key }
|
||||
end
|
||||
|
||||
def bool(value)
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'travis/api/v3/renderer/model_renderer'
|
|||
module Travis::API::V3
|
||||
class Renderer::Commit < Renderer::ModelRenderer
|
||||
representation(:minimal, :id, :sha, :ref, :message, :compare_url, :committed_at)
|
||||
representation(:standard, *representations[:minimal], :repository, :branch, :committer, :author)
|
||||
representation(:standard, *representations[:minimal], :committer, :author)
|
||||
|
||||
def sha
|
||||
model.commit
|
||||
|
|
|
@ -12,8 +12,9 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def self.representation(name, *fields)
|
||||
location = caller_locations.first
|
||||
fields.each do |field|
|
||||
class_eval "def #{field}; @model.#{field}; end" unless method_defined?(field)
|
||||
class_eval "def #{field}; @model.#{field}; end", location.path, location.lineno unless method_defined?(field)
|
||||
available_attributes << field.to_s
|
||||
end
|
||||
representations[name] ||= []
|
||||
|
|
Loading…
Reference in New Issue
Block a user