kopia lustrzana https://github.com/wagtail/wagtail
refactor(search/elastic): cleanup AtomicRebuilder.finish() method
rodzic
27f50a527c
commit
b70823f2aa
wagtail/wagtailsearch/backends
|
@ -574,19 +574,11 @@ class ElasticSearchAtomicIndexRebuilder(ElasticSearchIndexRebuilder):
|
|||
def finish(self):
|
||||
self.index.refresh()
|
||||
|
||||
# Create the alias if it doesnt exist yet
|
||||
if not self.alias.is_alias():
|
||||
# Make sure there isn't currently an index that clashes with alias
|
||||
# This can happen when the atomic rebuilder is first enabled
|
||||
self.alias.delete()
|
||||
if self.alias.is_alias():
|
||||
# Update existing alias, then delete the old index
|
||||
|
||||
# Create the alias
|
||||
self.index.put_alias(self.alias.name)
|
||||
|
||||
else:
|
||||
# Alias already exists, update it and delete old index
|
||||
|
||||
# Find index that alias currently points to, so we can delete it later
|
||||
# Find index that alias currently points to, we'll delete it after
|
||||
# updating the alias
|
||||
old_index = self.alias.aliased_indices()
|
||||
|
||||
# Update alias to point to new index
|
||||
|
@ -598,6 +590,18 @@ class ElasticSearchAtomicIndexRebuilder(ElasticSearchIndexRebuilder):
|
|||
if index.name != self.index.name:
|
||||
index.delete()
|
||||
|
||||
else:
|
||||
# self.alias doesn't currently refer to an alias in Elasticsearch.
|
||||
# This means that either nothing exists in ES with that name or
|
||||
# there is currently an index with the that name
|
||||
|
||||
# Run delete on the alias, just in case it is currently an index.
|
||||
# This happens on the first rebuild after switching ATOMIC_REBUILD on
|
||||
self.alias.delete()
|
||||
|
||||
# Create the alias
|
||||
self.index.put_alias(self.alias.name)
|
||||
|
||||
|
||||
class ElasticSearch(BaseSearch):
|
||||
index_class = ElasticSearchIndex
|
||||
|
|
Ładowanie…
Reference in New Issue