Project

General

Profile

Actions

Patch #37599

closed

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

Added by Go MAEDA over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

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,
Actions

Also available in: Atom PDF