Project

General

Profile

Actions

Patch #37599

closed

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

Added by Go MAEDA over 2 years ago. Updated about 2 years 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 #1

Updated by Go MAEDA about 2 years ago

  • Target version set to 5.1.0

Setting the target version to 5.1.0.

Actions #2

Updated by Go MAEDA about 2 years ago

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

Committed the patch.

Actions

Also available in: Atom PDF