diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 4f0eb634..17755dc8 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -4,6 +4,8 @@ class BacktraceJob < ApplicationJob class BacktraceException < RuntimeError; end + EMPTY_SOURCEMAP = { 'mappings' => '' }.freeze + queue_as :low_priority attr_reader :params, :site_id @@ -67,14 +69,18 @@ class BacktraceJob < ApplicationJob # @param [String] La URL del map # @return [Hash] def data(map) - return {} unless map.start_with? 'https://' + return EMPTY_SOURCEMAP unless map.start_with? 'https://' map += '.map' unless map.end_with? '.map' @data ||= {} + # TODO: Soportar ETags para la descarga, probablemente pasar a + # Faraday con caché para esto. @data[map] ||= FastJsonparser.parse(Rails.cache.fetch(map, expires_in: 12.hours) do Down.open(map).read end, symbolize_keys: false) + rescue Down::Error, FastJsonparser::Error + EMPTY_SOURCEMAP end # Asume que todos los sourcemaps comparten la misma URL, lo @@ -85,13 +91,8 @@ class BacktraceJob < ApplicationJob # # @return [SourceMap::Map] def sourcemap - @sourcemap ||= - begin - sources.map do |map| - SourceMap::Map.from_hash data(map) - rescue Down::Error, FastJsonparser::Error - SourceMap::Map.new - end.reduce(&:+) - end + @sourcemap ||= sources.map do |map| + SourceMap::Map.from_hash data(map) + end.reduce(&:+) end end