Sutou Kouhei 2019-06-10 12:51:21 +0900 (Mon, 10 Jun 2019) Revision: 1303ba0f4795d141c97db7f698a0af57a022e3e1 https://github.com/ranguba/chupa-text-http-server/commit/1303ba0f4795d141c97db7f698a0af57a022e3e1 Message: Release temporary resources immediately Modified files: Gemfile app/models/extraction.rb Modified: Gemfile (+1 -1) =================================================================== --- Gemfile 2019-03-29 12:42:55 +0900 (4e39f14) +++ Gemfile 2019-06-10 12:51:21 +0900 (8498836) @@ -62,7 +62,7 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'bootstrap' gem 'jquery-rails' -gem 'chupa-text', '>= 1.2.2'#, path: '../chupa-text' +gem 'chupa-text', '>= 1.2.6'#, path: '../chupa-text' local_gemfile = "#{__dir__}/Gemfile.local" if File.exist?(local_gemfile) eval(File.read(local_gemfile), binding, local_gemfile, 1) Modified: app/models/extraction.rb (+30 -19) =================================================================== --- app/models/extraction.rb 2019-03-29 12:42:55 +0900 (7cf6192) +++ app/models/extraction.rb 2019-06-10 12:51:21 +0900 (3d54f53) @@ -61,6 +61,32 @@ class Extraction return nil unless valid? extractor = self.class.extractor + create_data do |data| + formatter = ChupaText::Formatters::Hash.new + formatter.format_start(data) + max = data.max_body_size + size = 0 + begin + extractor.extract(data) do |extracted| + formatter.format_extracted(extracted) + body = extracted.body + extracted.release + if max and body + size += body.bytesize + break if size >= max + end + end + rescue ChupaText::Error => error + errors.add(:data, :invalid, message: error.message) + return nil + end + formatter.format_finish(data) + end + end + + private + def create_data + data = nil if @data data_uri = @uri data_uri = nil if data_uri.blank? @@ -69,11 +95,9 @@ class Extraction end data = ChupaText::VirtualFileData.new(data_uri, @data.to_io) data.mime_type =****@data*****_type if****@data*****_type - setup_data(data) else begin data = ChupaText::InputData.new(@uri) - setup_data(data) rescue ChupaText::DownloadError => error errors.add(:uri, :invalid, message: error.message) return nil @@ -82,27 +106,14 @@ class Extraction return nil end end - formatter = ChupaText::Formatters::Hash.new - formatter.format_start(data) - max = data.max_body_size - size = 0 begin - extractor.extract(data) do |extracted| - formatter.format_extracted(extracted) - body = extracted.body - if max and body - size += body.bytesize - break if size >= max - end - end - rescue ChupaText::Error => error - errors.add(:data, :invalid, message: error.message) - return nil + setup_data(data) + yield(data) + ensure + data.release end - formatter.format_finish(data) end - private def setup_data(data) data.max_body_size = max_body_size data.timeout = @timeout -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190610/6b8b5847/attachment-0001.html>