Merge fa06bf61e324bd046795a0c3daac0b42ef89845e into 7db80f673d037ed841bef8e8a93dcda21380e135

This commit is contained in:
Ben Walsh 2022-04-12 13:21:57 -07:00 committed by GitHub
commit 670dd0cc36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,29 +95,24 @@ module FastJsonapi
# #
# @param options [Hash] default cache options # @param options [Hash] default cache options
# @param fieldset [Array, nil] passed fieldset values # @param fieldset [Array, nil] passed fieldset values
# @param includes_list [Array, nil] passed included values # @param _includes_list [Array, nil] passed included values
# @param params [Hash] the serializer params # @param _params [Hash] the serializer params
# #
# @return [Hash] processed options hash # @return [Hash] processed options hash
# rubocop:disable Lint/UnusedMethodArgument def record_cache_options(options, fieldset, _includes_list, _params)
def record_cache_options(options, fieldset, includes_list, params)
return options unless fieldset
options = options ? options.dup : {} options = options ? options.dup : {}
options[:namespace] ||= 'jsonapi-serializer' namespace = [options[:namespace] ||= 'jsonapi-serializer']
if fieldset
fieldset_key = fieldset.join('_') fieldset_key = fieldset.join('_')
# Use a fixed-length fieldset key if the current length is more than
# Use a fixed-length fieldset key if the current length is more than # the length of a SHA1 digest
# the length of a SHA1 digest fieldset_key = Digest::SHA1.hexdigest(fieldset_key) if fieldset_key.length > 40
if fieldset_key.length > 40 namespace.push("fieldset:#{fieldset_key}")
fieldset_key = Digest::SHA1.hexdigest(fieldset_key)
end end
namespace.push("serializer:#{name.urlize}")
options[:namespace] = "#{options[:namespace]}-fieldset:#{fieldset_key}" options[:namespace] = [namespace.compact.join('-')]
options options
end end
# rubocop:enable Lint/UnusedMethodArgument
def id_from_record(record, params) def id_from_record(record, params)
return FastJsonapi.call_proc(record_id, record, params) if record_id.is_a?(Proc) return FastJsonapi.call_proc(record_id, record, params) if record_id.is_a?(Proc)