class ActiverecordReindex::Adapter
Public Class Methods
_check_elasticsearch_connection(klass)
click to toggle source
check if record of this class can be reindexed == check if klass inherits from elasticsearch-model base class
# File lib/activerecord_reindex/adapter.rb, line 13 def self._check_elasticsearch_connection(klass) klass < Elasticsearch::Model end
call(request_record, record: nil, records: nil)
click to toggle source
updates index directly in elasticsearch through Elasticsearch::Model
instance method if class not inherited from Elasticsearch::Model
it skips since it cannot be reindexed
***nasty-stuff***
hooking into update_document has sudden side-effect if associations defined two-way they will trigger reindex recursively and result in StackLevelTooDeep hence to prevent this we're passing request_record to adapter request record is record that initted reindex for current record as association we will skip it in associations reindex to prevent recursive reindex and StackLevelTooDeep error
# File lib/activerecord_reindex/adapter.rb, line 29 def self.call(request_record, record: nil, records: nil) if record return unless _check_elasticsearch_connection(record.class) _single_reindex(request_record, record) elsif records && record = records.first return unless _check_elasticsearch_connection(record.class) _mass_reindex(request_record, record.class.name, records) end end