From 7781ed8f5c9997a3ce7317f34f64edd590b2c3d3 Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Sat, 20 Jul 2024 18:23:12 -0300 Subject: [PATCH] feat: do not call api when document is set to ignore --- lib/esse/active_record/callbacks/indexing_on_create.rb | 2 +- lib/esse/active_record/callbacks/indexing_on_destroy.rb | 2 +- lib/esse/active_record/callbacks/indexing_on_update.rb | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/esse/active_record/callbacks/indexing_on_create.rb b/lib/esse/active_record/callbacks/indexing_on_create.rb index 19b3a0c..f987506 100644 --- a/lib/esse/active_record/callbacks/indexing_on_create.rb +++ b/lib/esse/active_record/callbacks/indexing_on_create.rb @@ -6,7 +6,7 @@ class IndexingOnCreate < Callback def call(model) record = block_result || model document = repo.serialize(record) - repo.index.index(document, **options) if document + repo.index.index(document, **options) if document && !document.ignore_on_index? true end end diff --git a/lib/esse/active_record/callbacks/indexing_on_destroy.rb b/lib/esse/active_record/callbacks/indexing_on_destroy.rb index d092b9f..0913614 100644 --- a/lib/esse/active_record/callbacks/indexing_on_destroy.rb +++ b/lib/esse/active_record/callbacks/indexing_on_destroy.rb @@ -6,7 +6,7 @@ class IndexingOnDestroy < Callback def call(model) record = block_result || model document = repo.serialize(record) - repo.index.delete(document, **options) if document + repo.index.delete(document, **options) if document && !document.ignore_on_delete? true rescue Esse::Transport::NotFoundError true diff --git a/lib/esse/active_record/callbacks/indexing_on_update.rb b/lib/esse/active_record/callbacks/indexing_on_update.rb index 99ca182..0901b38 100644 --- a/lib/esse/active_record/callbacks/indexing_on_update.rb +++ b/lib/esse/active_record/callbacks/indexing_on_update.rb @@ -41,6 +41,8 @@ def call(model) protected def update_document(document) + return if document.ignore_on_index? + if update_with == :update begin repo.index.update(document, **options)