From e2e3b6242abbc975ef48c4d6d4ae0c8992baf345 Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Mon, 19 Aug 2024 16:55:51 -0300 Subject: [PATCH] minor refactoring --- lib/esse/document.rb | 2 +- lib/esse/index/documents.rb | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/esse/document.rb b/lib/esse/document.rb index 9c3a413..9c3327a 100644 --- a/lib/esse/document.rb +++ b/lib/esse/document.rb @@ -88,7 +88,7 @@ def eql?(other, match_lazy_doc_header: false) if match_lazy_doc_header && other.is_a?(LazyDocumentHeader) other.eql?(self) else - other.is_a?(self.class) && ( + other.is_a?(Esse::Document) && ( id.to_s == other.id.to_s && type == other.type && routing == other.routing && meta == other.meta && source == other.source ) end diff --git a/lib/esse/index/documents.rb b/lib/esse/index/documents.rb index b6f9f46..cd9b971 100644 --- a/lib/esse/index/documents.rb +++ b/lib/esse/index/documents.rb @@ -294,13 +294,10 @@ def import(*repo_types, context: {}, eager_load_lazy_attributes: false, update_l collection_context ||= {} entries = [*batch].map { |entry| repo.serialize(entry, **collection_context) }.compact - if lazy_attrs_to_eager_load - attrs = lazy_attrs_to_eager_load.is_a?(Array) ? lazy_attrs_to_eager_load : repo.lazy_document_attribute_names(lazy_attrs_to_eager_load) - attrs.each do |attr_name| - repo.retrieve_lazy_attribute_values(attr_name, entries).each do |doc_header, value| - doc = entries.find { |d| d.eql?(doc_header, match_lazy_doc_header: true) } - doc&.mutate(attr_name) { value } - end + lazy_attrs_to_eager_load.each do |attr_name| + repo.retrieve_lazy_attribute_values(attr_name, entries).each do |doc_header, value| + doc = entries.find { |d| d.eql?(doc_header, match_lazy_doc_header: true) } + doc&.mutate(attr_name) { value } end end