diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-09-12 17:54:01 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-09-12 17:54:01 +0100 |
commit | 77a22824fb23bc25945adf2b96feb55b004bdb8a (patch) | |
tree | 5962b090ca4a705386876352f4d316dcf2a31131 /app/models | |
parent | 98fe4eab026e3fe2545bffaa8f14a128ba407d62 (diff) |
Memoize the notes_without_html calculated value for the life of the model instance - no need to keep applying the regex if called multiple times e.g. in a view.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_body.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 575e365ac..e5ef26047 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -47,6 +47,7 @@ class PublicBody < ActiveRecord::Base has_tag_string before_save :set_api_key, :set_default_publication_scheme + translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme # Convenience methods for creating/editing translations via forms @@ -553,7 +554,7 @@ class PublicBody < ActiveRecord::Base def notes_without_html # assume notes are reasonably behaved HTML, so just use simple regexp on this - self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "") + @notes_without_html ||= (self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "")) end def json_for_api |