Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazify calculating caller file digest until used #1687

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Breaking changes:
- [#1574](https://github.com/rails-api/active_model_serializers/pull/1574) Default key case for the JsonApi adapter changed to dashed. (@remear)

Features:
- [#1687](https://github.com/rails-api/active_model_serializers/pull/1687) Only calculate `_cache_digest` (in `cache_key`) when `skip_digest` is false. (@bf4)
- [#1647](https://github.com/rails-api/active_model_serializers/pull/1647) Restrict usage of `serializable_hash` options
to the ActiveModel::Serialization and ActiveModel::Serializers::JSON interface. (@bf4)
- [#1645](https://github.com/rails-api/active_model_serializers/pull/1645) Transform keys referenced in values. (@remear)
Expand Down
12 changes: 9 additions & 3 deletions lib/active_model/serializer/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ module Caching
# force
# race_condition_ttl
# Passed to ::_cache as
# serializer._cache.fetch(cache_key, @klass._cache_options)
serializer.class_attribute :_cache_digest # @api private : Generated
# serializer.cache_store.fetch(cache_key, @klass._cache_options)
# Passed as second argument to serializer.cache_store.fetch(cache_key, self.class._cache_options)
serializer.class_attribute :_cache_digest_file_path # @api private : Derived at inheritance
end
end

Expand All @@ -42,7 +43,12 @@ module ClassMethods
def inherited(base)
super
caller_line = caller[1]
base._cache_digest = digest_caller_file(caller_line)
base._cache_digest_file_path = caller_line
end

def _cache_digest
return @_cache_digest if defined?(@_cache_digest)
@_cache_digest = digest_caller_file(_cache_digest_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be rewritten as @_cache_digest ||= digest_caller_file(_cache_digest_file_path) instead of the two lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It should never be nilnor empty
On Mon, Apr 18, 2016 at 6:04 PM Lucas Hosseini notifications@github.com
wrote:

In lib/active_model/serializer/caching.rb
#1687 (comment)
:

@@ -42,7 +43,12 @@ module ClassMethods
def inherited(base)
super
caller_line = caller[1]

  •      base._cache_digest = digest_caller_file(caller_line)
    
  •      base._cache_digest_file_path = caller_line
    
  •    end
    
  •    def _cache_digest
    
  •      return @_cache_digest if defined?(@_cache_digest)
    
  •      @_cache_digest = digest_caller_file(_cache_digest_file_path)
    

Could be rewritten as @_cache_digest ||=
digest_caller_file(_cache_digest_file_path) instead of the two lines.


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/rails-api/active_model_serializers/pull/1687/files/1d24c9708ae802ec449664f82746d93d8fa345c0#r60149660

end

# Hashes contents of file for +_cache_digest+
Expand Down