Class: ActiverecordReindex::Adapter
- Inherits:
-
Object
- Object
- ActiverecordReindex::Adapter
- Defined in:
- lib/activerecord_reindex/adapter.rb
Direct Known Subclasses
Class Method Summary collapse
-
._check_elasticsearch_connection(klass) ⇒ Object
check if record of this class can be reindexed == check if klass inherits from elasticsearch-model base class.
-
.call(request_record, record: nil, records: nil) ⇒ Object
updates index directly in elasticsearch through Elasticsearch::Model instance method if class not inherited from Elasticsearch::Model it skips since it cannot be reindexed.
Class Method Details
._check_elasticsearch_connection(klass) ⇒ Object
check if record of this class can be reindexed == check if klass inherits from elasticsearch-model base class
13 14 15 |
# 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) ⇒ Object
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
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |