From 5dcfd43d932b28953f8657f0fa7eab19bf67d09c Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 2 Aug 2021 22:14:26 -0700 Subject: [PATCH] Avoid duplicate GET requests when retrieving body Previously the response body would be loaded twice in memory whenever `GoogleJSON::File#body` was called. This was happening because inside the ternary condition, `file.body` was recursively calling itself twice even though the body was already loaded. We rewrite this method to be simpler and to have a proper base condition. Closes https://github.com/fog/fog-google/issues/541 --- lib/fog/storage/google_json/models/file.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/fog/storage/google_json/models/file.rb b/lib/fog/storage/google_json/models/file.rb index ea61311f0..870b2e4de 100644 --- a/lib/fog/storage/google_json/models/file.rb +++ b/lib/fog/storage/google_json/models/file.rb @@ -45,7 +45,16 @@ def predefined_acl=(new_predefined_acl) end def body - last_modified && (file = collection.get(identity)) ? attributes[:body] ||= file.body : attributes[:body] ||= "" + return attributes[:body] if attributes.key?(:body) + + file = collection.get(identity) + + attributes[:body] = + if file + file.attributes[:body] + else + "" + end end def body=(new_body)