mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Cache tags_text to avoid computing tags each time when logging
This commit is contained in:
parent
b8d29f35f0
commit
05060ddba1
1 changed files with 10 additions and 5 deletions
|
@ -32,15 +32,18 @@ module ActiveSupport
|
|||
|
||||
def push_tags(*tags)
|
||||
tags.flatten.reject(&:blank?).tap do |new_tags|
|
||||
@tags_text = nil
|
||||
current_tags.concat new_tags
|
||||
end
|
||||
end
|
||||
|
||||
def pop_tags(size = 1)
|
||||
@tags_text = nil
|
||||
current_tags.pop size
|
||||
end
|
||||
|
||||
def clear_tags!
|
||||
@tags_text = nil
|
||||
current_tags.clear
|
||||
end
|
||||
|
||||
|
@ -51,11 +54,13 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
def tags_text
|
||||
tags = current_tags
|
||||
if tags.one?
|
||||
"[#{tags[0]}] "
|
||||
elsif tags.any?
|
||||
tags.collect { |tag| "[#{tag}] " }.join
|
||||
@tags_text ||= begin
|
||||
tags = current_tags
|
||||
if tags.one?
|
||||
"[#{tags[0]}] "
|
||||
elsif tags.any?
|
||||
tags.collect { |tag| "[#{tag}] " }.join
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue