Skip to content

Commit

Permalink
Merge pull request #871 from samvera/solr_performance
Browse files Browse the repository at this point in the history
Improve ModelConverter performance.
  • Loading branch information
tpendragon authored Sep 2, 2021
2 parents 68c2a17 + ef51574 commit b519dd2
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions lib/valkyrie/persistence/solr/model_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def attribute_hash
properties.each_with_object({}) do |property, hsh|
next if property == Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK
attr = resource_attributes[property]
next if attr.nil?
mapper_val = SolrMapperValue.for(Property.new(property, attr)).result
unless mapper_val.respond_to?(:apply_to)
raise "Unable to cast #{resource_attributes[:internal_resource]}#" \
Expand Down Expand Up @@ -162,8 +163,8 @@ class SolrRow
# @param values [Array] Values to index into the given fields.
def initialize(key:, fields:, values:)
@key = key
@fields = Array.wrap(fields)
@values = Array.wrap(values)
@fields = fields
@values = values
end

# @param hsh [Hash] The solr hash to apply to.
Expand Down Expand Up @@ -241,7 +242,7 @@ def self.handles?(value)
# @see https://github.com/samvera-labs/valkyrie/blob/main/solr/config/schema.xml
# @return [SolrRow]
def result
SolrRow.new(key: value.key, fields: ["tsim"], values: "serialized-#{value.value.to_json}")
SolrRow.new(key: value.key, fields: ["tsim"], values: ["serialized-#{value.value.to_json}"])
end
end

Expand All @@ -267,24 +268,6 @@ def result
end
end

# Skips nil values.
class NilPropertyValue < ::Valkyrie::ValueMapper
SolrMapperValue.register(self)

# Determines whether or not a Property value responds as nil
# @param [Object] value
# @return [Boolean]
def self.handles?(value)
value.is_a?(Property) && value.value.nil?
end

# Constructs a SolrRow object for a Property with a nil value
# @return [SolrRow]
def result
SolrRow.new(key: value.key, fields: [], values: nil)
end
end

# Casts {Valkyrie::ID} values into a recognizable string in solr.
class IDPropertyValue < ::Valkyrie::ValueMapper
SolrMapperValue.register(self)
Expand Down Expand Up @@ -423,7 +406,7 @@ def self.handles?(value)
# Constructs a SolrRow object with the String values and Solr field settings
# @return [SolrRow]
def result
SolrRow.new(key: value.key, fields: fields, values: value.value)
SolrRow.new(key: value.key, fields: fields, values: [value.value])
end

# Generates the Solr fields used during the indexing
Expand Down

0 comments on commit b519dd2

Please sign in to comment.