Skip to content

Commit

Permalink
feat: adjusting plugin according the core esse api
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 23, 2024
1 parent a70e203 commit 4313e54
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/marcosgz/esse.git
revision: 56e9a200a1d88c2163989854e8cf2fca952503a0
revision: 8fd302274e9c9c0dcdeec7b8f6ffafc05234014b
branch: main
specs:
esse (0.4.0.rc1)
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/async_indexing/actions/bulk_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.call(index_class_name, repo_name, ids, options = {})

index_class, _repo_class = CoerceIndexRepository.call(index_class_name, repo_name)
bulk_opts = Esse::HashUtils.deep_transform_keys(options, &:to_sym)
index_class.bulk(**bulk_opts, delete: docs.map(&:to_doc))
index_class.bulk(**bulk_opts, delete: docs.map(&:doc_header))
docs.size
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/esse/async_indexing/actions/bulk_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Esse::AsyncIndexing::Actions
class BulkUpdate
DOC_ARGS = %i[lazy_attributes context]

def self.call(index_class_name, repo_name, ids, options = {})
ids = Array(ids)
Expand All @@ -14,8 +13,11 @@ def self.call(index_class_name, repo_name, ids, options = {})
if (context = bulk_opts.delete(:context))
find_opts.merge!(context)
end
if (lazy_attributes = bulk_opts.delete(:lazy_attributes))
find_opts[:lazy_attributes] = lazy_attributes
if (val = bulk_opts.delete(:eager_load_lazy_attributes))
find_opts[:eager_load_lazy_attributes] = val
end
if (val = bulk_opts.delete(:preload_lazy_attributes))
find_opts[:preload_lazy_attributes] = val
end
find_opts[:id] = ids

Expand Down
2 changes: 1 addition & 1 deletion lib/esse/async_indexing/actions/delete_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Esse::AsyncIndexing::Actions
class DeleteDocument
DOC_ARGS = %i[lazy_attributes]
DOC_ARGS = %i[eager_load_lazy_attributes preload_lazy_attributes]

def self.call(index_class_name, repo_name, document_id, options = {})
index_class, _repo_class = CoerceIndexRepository.call(index_class_name, repo_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/async_indexing/actions/index_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Esse::AsyncIndexing::Actions
class IndexDocument
DOC_ARGS = %i[lazy_attributes]
DOC_ARGS = %i[eager_load_lazy_attributes preload_lazy_attributes]

def self.call(index_class_name, repo_name, document_id, options = {})
index_class, repo_class = CoerceIndexRepository.call(index_class_name, repo_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/async_indexing/actions/update_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Esse::AsyncIndexing::Actions
class UpdateDocument
DOC_ARGS = %i[lazy_attributes]
DOC_ARGS = %i[eager_load_lazy_attributes preload_lazy_attributes]

def self.call(index_class_name, repo_name, document_id, options = {})
index_class, repo_class = CoerceIndexRepository.call(index_class_name, repo_name)
Expand Down
3 changes: 1 addition & 2 deletions lib/esse/async_indexing/actions/upsert_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module Esse::AsyncIndexing::Actions
class UpsertDocument
DOC_ARGS = %i[lazy_attributes]
# OPERATIONS = %w[index update delete]
DOC_ARGS = %i[eager_load_lazy_attributes preload_lazy_attributes]

def self.call(index_class_name, repo_name, document_id, operation = "index", options = {})
case operation
Expand Down
4 changes: 2 additions & 2 deletions spec/esse/async_indexing/actions/bulk_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{update: {_id: 1, data: {doc: {name: "City 1"}}}}
]
).and_return("items" => [{}])
expect(described_class.call("GeosIndex", "city", [1], lazy_attributes: false)).to eq(1)
expect(described_class.call("GeosIndex", "city", [1], eager_load_lazy_attributes: false)).to eq(1)
end

it "updates all documents with eager loading lazy attributes" do
Expand All @@ -65,7 +65,7 @@
{update: {_id: 1, data: {doc: {name: "City 1", total_venues: 10}}}}
]
).and_return("items" => [{}])
expect(described_class.call("GeosIndex", "city", [1], lazy_attributes: true)).to eq(1)
expect(described_class.call("GeosIndex", "city", [1], eager_load_lazy_attributes: true)).to eq(1)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/esse/async_indexing/actions/delete_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
refresh: true
).and_return("result" => "deleted")

expect(described_class.call("VenuesIndex", "venue", hotel[:id], lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:deleted)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:deleted)
end
end
end
2 changes: 1 addition & 1 deletion spec/esse/async_indexing/actions/index_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
refresh: true
).and_return("result" => "created", "_id" => hotel[:id])

expect(described_class.call("VenuesIndex", "venue", hotel[:id], lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
end

it "does not send the :index request if the document is not found" do
Expand Down
2 changes: 1 addition & 1 deletion spec/esse/async_indexing/actions/update_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
refresh: true
).and_return("result" => "updated", "_id" => hotel[:id])

expect(described_class.call("VenuesIndex", "venue", hotel[:id], lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
end

it "does not send a update request if the document is not found" do
Expand Down
6 changes: 3 additions & 3 deletions spec/esse/async_indexing/actions/upsert_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
refresh: true
).and_return("result" => "created", "_id" => hotel[:id])

expect(described_class.call("VenuesIndex", "venue", hotel[:id], "index", lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], "index", eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
end
end

Expand All @@ -67,7 +67,7 @@
refresh: true
).and_return("result" => "deleted")

expect(described_class.call("VenuesIndex", "venue", hotel[:id], "delete", lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:deleted)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], "delete", eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:deleted)
end
end

Expand Down Expand Up @@ -102,7 +102,7 @@
refresh: true
).and_return("result" => "updated", "_id" => hotel[:id])

expect(described_class.call("VenuesIndex", "venue", hotel[:id], "update", lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
expect(described_class.call("VenuesIndex", "venue", hotel[:id], "update", eager_load_lazy_attributes: false, refresh: true, suffix: "2024")).to eq(:indexed)
end
end

Expand Down

0 comments on commit 4313e54

Please sign in to comment.