v3: use cached_matrix_ids for build.jobs if only job ids are being loaded

This commit is contained in:
Konstantin Haase 2015-09-03 15:03:12 +02:00
parent f57f62ba75
commit 2891dd640a
3 changed files with 32 additions and 2 deletions

View File

@ -20,6 +20,16 @@ module Travis::API::V3
read_attribute(:branch)
end
def job_ids
return super unless cached = cached_matrix_ids
# AR 3.2 does not handle pg arrays and the plugins supporting them
# do not work well with jdbc drivers
# TODO: remove this once we're on >= 4.0
cached = cached.gsub(/^{|}$/, '').split(',').map(&:to_i) unless cached.is_a? Array
cached
end
def branch_name=(value)
write_attribute(:branch, value)
end

View File

@ -3,6 +3,26 @@ require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Build < Renderer::ModelRenderer
representation(:minimal, :id, :number, :state, :duration, :event_type, :previous_state, :started_at, :finished_at, :jobs)
representation(:standard, *representations[:minimal], :repository, :branch, :commit )
representation(:standard, *representations[:minimal], :repository, :branch, :commit)
def jobs
return model.jobs if include_full_jobs?
model.job_ids.map { |id| job(id) }
end
private def include_full_jobs?
return true if include? 'build.job'.freeze
return true if include.any? { |i| i.start_with? 'job.'.freeze }
return true if included.any? { |i| i.is_a? Models::Job and i.source_id == model.id }
end
private def job(id)
{
"@type" => "job",
:@href => Renderer.href(:job, script_name: script_name, id: id),
"@representation" => "minimal",
"id" => id
}
end
end
end

View File

@ -3,6 +3,6 @@ require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Job < Renderer::ModelRenderer
representation(:minimal, :id)
representation(:standard, *representations[:minimal], :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner )
representation(:standard, *representations[:minimal], :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner)
end
end