Patch #37599

Remove extra call of Attachment#thumbnailable? in AttachmentsController#thumbnail

Added by Go MAEDA about 1 month ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Code cleanup/refactoring
Target version:5.1.0

Description

In AttachmentsController#thumbnail, you can find the following code. It checks the return value of @attachment.thumbnailable?.

  def thumbnail
    if @attachment.thumbnailable? && tbnail = @attachment.thumbnail(:size => params[:size])

However, it is unnecessary because Attachment#thumbnailable? is also called in Attachmnet#thumbnail as follows.

  def thumbnail(options={})
    if thumbnailable? && readable?

Therefore, we can safely remove the call of Attachment#thumbnailable?. See the patch below.

diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index aa8bbeec9..612e070d2 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -83,7 +83,7 @@ class AttachmentsController < ApplicationController
   end

   def thumbnail
-    if @attachment.thumbnailable? && tbnail = @attachment.thumbnail(:size => params[:size])
+    if (tbnail = @attachment.thumbnail(:size => params[:size]))
       if stale?(:etag => tbnail, :template => false)
         send_file(
           tbnail,

Associated revisions

Revision 21790
Added by Go MAEDA about 1 month ago

Remove extra call of Attachment#thumbnailable? in AttachmentsController#thumbnail (#37599).

Patch by Go MAEDA.

History

#1 Updated by Go MAEDA about 1 month ago

  • Target version set to 5.1.0

Setting the target version to 5.1.0.

#2 Updated by Go MAEDA about 1 month ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch.

Also available in: Atom PDF