diff options
author | Akira Matsuda <ronnie@dio.jp> | 2019-07-31 09:29:38 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2019-07-31 11:51:59 +0900 |
commit | 05060ddba170ccb3ba9ce48555ed45400fe1ea96 (patch) | |
tree | 916fff97a5dbd438fe6e6a6145a51dedba640e02 /activesupport | |
parent | b8d29f35f0ef36bfe8c3d3a27ca0b80d02c4a0b0 (diff) | |
download | rails-05060ddba170ccb3ba9ce48555ed45400fe1ea96.tar.gz rails-05060ddba170ccb3ba9ce48555ed45400fe1ea96.tar.bz2 rails-05060ddba170ccb3ba9ce48555ed45400fe1ea96.zip |
Cache tags_text to avoid computing tags each time when logging
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/tagged_logging.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index d8a86d997e..75a7ca24c2 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -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 |