Commit 8f3d6b313cd2d8d5a2071b38f4735b40dbb5a9c6

Authored by Rodrigo Souto
1 parent 4bbfef7e

file-presenter: do not wrap Articles that are not files

This check is redundant but speeds up blog_page.

ActionItem3201
app/helpers/blog_helper.rb
... ... @@ -45,9 +45,9 @@ module BlogHelper
45 45  
46 46 def display_post(article, format = 'full')
47 47 no_comments = (format == 'full') ? false : true
  48 + title = article_title(article, :no_comments => no_comments)
48 49 html = send("display_#{format}_format", FilePresenter.for(article)).html_safe
49   -
50   - article_title(article, :no_comments => no_comments) + html
  50 + title + html
51 51 end
52 52  
53 53 def display_full_format(article)
... ...
lib/file_presenter.rb
... ... @@ -6,7 +6,9 @@ class FilePresenter
6 6 # one accepts it. That behave allow to give any model to this class,
7 7 # like a Article and have no trouble with that.
8 8 def self.for(f)
9   - return f if f.is_a? FilePresenter
  9 + #FIXME This check after the || is redundant but increases the blog_page
  10 + # speed considerably.
  11 + return f if f.is_a?(FilePresenter ) || (!f.kind_of?(UploadedFile) && !f.kind_of?(Image))
10 12 klass = FilePresenter.subclasses.sort_by {|class_name|
11 13 class_name.constantize.accepts?(f) || 0
12 14 }.last.constantize
... ...