mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Cleanup update_index command
This commit is contained in:
parent
1aa0817a03
commit
9de25998fe
@ -9,14 +9,7 @@ from wagtail.wagtailsearch.index import get_indexed_models
|
|||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def get_object_list(self):
|
def update_backend(self, backend_name):
|
||||||
# Return list of (model_name, queryset) tuples
|
|
||||||
return [
|
|
||||||
(model, model.get_indexed_objects())
|
|
||||||
for model in get_indexed_models()
|
|
||||||
]
|
|
||||||
|
|
||||||
def update_backend(self, backend_name, object_list):
|
|
||||||
# Print info
|
# Print info
|
||||||
self.stdout.write("Updating backend: " + backend_name)
|
self.stdout.write("Updating backend: " + backend_name)
|
||||||
|
|
||||||
@ -34,7 +27,7 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write(backend_name + ": Starting rebuild")
|
self.stdout.write(backend_name + ": Starting rebuild")
|
||||||
index = rebuilder.start()
|
index = rebuilder.start()
|
||||||
|
|
||||||
for model, queryset in object_list:
|
for model in get_indexed_models():
|
||||||
self.stdout.write(backend_name + ": Indexing model '%s.%s'" % (
|
self.stdout.write(backend_name + ": Indexing model '%s.%s'" % (
|
||||||
model._meta.app_label,
|
model._meta.app_label,
|
||||||
model.__name__,
|
model.__name__,
|
||||||
@ -45,7 +38,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Add items (1000 at a time)
|
# Add items (1000 at a time)
|
||||||
count = 0
|
count = 0
|
||||||
for chunk in self.print_iter_progress(self.queryset_chunks(queryset)):
|
for chunk in self.print_iter_progress(self.queryset_chunks(model.get_indexed_objects())):
|
||||||
index.add_items(model, chunk)
|
index.add_items(model, chunk)
|
||||||
count += len(chunk)
|
count += len(chunk)
|
||||||
|
|
||||||
@ -63,9 +56,6 @@ class Command(BaseCommand):
|
|||||||
help="Specify a backend to update")
|
help="Specify a backend to update")
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
# Get object list
|
|
||||||
object_list = self.get_object_list()
|
|
||||||
|
|
||||||
# Get list of backends to index
|
# Get list of backends to index
|
||||||
if options['backend_name']:
|
if options['backend_name']:
|
||||||
# index only the passed backend
|
# index only the passed backend
|
||||||
@ -79,7 +69,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Update backends
|
# Update backends
|
||||||
for backend_name in backend_names:
|
for backend_name in backend_names:
|
||||||
self.update_backend(backend_name, object_list)
|
self.update_backend(backend_name)
|
||||||
|
|
||||||
def print_newline(self):
|
def print_newline(self):
|
||||||
self.stdout.write('')
|
self.stdout.write('')
|
||||||
|
Loading…
Reference in New Issue
Block a user