Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzasa committed Dec 20, 2021
1 parent 5fe694f commit d662b9c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 209 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ field :hierarchy_link, type: :join, relations: {question: %i[answer comment], an
```
assuming you have `comment_type` and `commented_id` fields in your model.

Note that when you remove or reindex a parent, it's children and grandchildren will be removed/reindexed as well.
This may require additional queries to the database and to elastisearch.
Note that when you reindex a parent, it's children and grandchildren will be reindexed as well.
This may require additional queries to the primary database and to elastisearch.

Also note that the join field doesn't support crutches (it should be a field directly defined on the model).

Expand All @@ -473,7 +473,7 @@ class ProductsIndex < Chewy::Index
field :name
field :category_names, value: ->(product) { product.categories.map(&:name) } # or shorter just -> { categories.map(&:name) }
end
```
`
Then the Chewy reindexing flow will look like the following pseudo-code:
Expand Down
12 changes: 3 additions & 9 deletions lib/chewy/index/import/bulk_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def reindex_descendants(root)
end

def delete_entry(object)
delete_single_entry(object) # + delete_descendants(object)
delete_single_entry(object)
end

def delete_single_entry(object, root: object)
Expand All @@ -115,20 +115,13 @@ def delete_single_entry(object, root: object)
[{delete: entry}]
end

def delete_descendants(root)
return [] unless root.respond_to?(:id)

load_descendants(root).flat_map do |object|
delete_single_entry(object, root: root)
end
end

def load_descendants(root)
root_type = join_field_type(root)
return [] unless root_type

descendant_ids = []
grouped_parents = {root_type => [root.id]}
# iteratively fetch all the descendants (with grouped_parents as a queue for next iteration)
until grouped_parents.empty?
children_data = grouped_parents.flat_map do |parent_type, parent_ids|
@index.query(
Expand All @@ -151,6 +144,7 @@ def load_descendants(root)
grouped_parents[name] << id
end
end
# query the primary database to load the descentants' records
@index.adapter.load(descendant_ids, _index: @index.base_name, raw_import: @index._default_import_options[:raw_import])
end

Expand Down
80 changes: 0 additions & 80 deletions manual.rb

This file was deleted.

117 changes: 0 additions & 117 deletions queries.sh

This file was deleted.

0 comments on commit d662b9c

Please sign in to comment.