kopia lustrzana https://github.com/wagtail/wagtail
Support "--verbosity 0" on update_index command
- Ensure that the `update_index` command can run without console output if called with `--verbosity 0` - rebase of #4401pull/9369/head
rodzic
398c575153
commit
6341d90f56
|
@ -44,6 +44,7 @@ Changelog
|
|||
* Add anchor links to StreamField blocks so users can navigate straight to a given block (Thibaud Colas)
|
||||
* Support "Ctrl + f" in-page search within collapsed StreamField blocks (Thibaud Colas)
|
||||
* Remember the last opened side panel in the page editor, activating it on page load (Sage Abdullah)
|
||||
* Ensure that the `update_index` command can run without console output if called with `--verbosity 0` (Ben Sturmfels, Oliver Parker)
|
||||
* Fix: Prevent `PageQuerySet.not_public` from returning all pages when no page restrictions exist (Mehrdad Moradizadeh)
|
||||
* Fix: Ensure that duplicate block ids are unique when duplicating stream blocks in the page editor (Joshua Munn)
|
||||
* Fix: Revise colour usage so that privacy & locked indicators can be seen in Windows High Contrast mode (LB (Ben Johnston))
|
||||
|
|
|
@ -97,6 +97,16 @@ You can prevent the `update_index` command from indexing any data by using the `
|
|||
python manage.py update_index --schema-only
|
||||
```
|
||||
|
||||
### Silencing the command
|
||||
|
||||
You can prevent logs to the console by providing `--verbosity 0` as an argument:
|
||||
|
||||
```console
|
||||
$ python manage.py update_index --verbosity 0
|
||||
```
|
||||
|
||||
If this is omitted or provided with any number above 0 it will produce the same logs.
|
||||
|
||||
(wagtail_update_index)=
|
||||
|
||||
## wagtail_update_index
|
||||
|
|
|
@ -66,6 +66,7 @@ This feature was developed by Karl Hobley and Matt Westcott.
|
|||
* Add anchor links to StreamField blocks so users can navigate straight to a given block (Thibaud Colas)
|
||||
* Support "Ctrl + f" in-page search within collapsed StreamField blocks (Thibaud Colas)
|
||||
* Remember the last opened side panel in the page editor, activating it on page load (Sage Abdullah)
|
||||
* Ensure that the [`update_index`](update_index) command can run without console output if called with `--verbosity 0` (Ben Sturmfels, Oliver Parker)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
|
|
|
@ -54,25 +54,30 @@ def group_models_by_index(backend, models):
|
|||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def write(self, *args, **kwargs):
|
||||
"""Helper function that respects verbosity when printing."""
|
||||
if self.verbosity > 0:
|
||||
self.stdout.write(*args, **kwargs)
|
||||
|
||||
def update_backend(
|
||||
self, backend_name, schema_only=False, chunk_size=DEFAULT_CHUNK_SIZE
|
||||
):
|
||||
self.stdout.write("Updating backend: " + backend_name)
|
||||
self.write("Updating backend: " + backend_name)
|
||||
|
||||
backend = get_search_backend(backend_name)
|
||||
|
||||
if not backend.rebuilder_class:
|
||||
self.stdout.write("Backend '%s' doesn't require rebuilding" % backend_name)
|
||||
self.write("Backend '%s' doesn't require rebuilding" % backend_name)
|
||||
return
|
||||
|
||||
models_grouped_by_index = group_models_by_index(
|
||||
backend, get_indexed_models()
|
||||
).items()
|
||||
if not models_grouped_by_index:
|
||||
self.stdout.write(backend_name + ": No indices to rebuild")
|
||||
self.write(backend_name + ": No indices to rebuild")
|
||||
|
||||
for index, models in models_grouped_by_index:
|
||||
self.stdout.write(backend_name + ": Rebuilding index %s" % index.name)
|
||||
self.write(backend_name + ": Rebuilding index %s" % index.name)
|
||||
|
||||
# Start rebuild
|
||||
rebuilder = backend.rebuilder_class(index)
|
||||
|
@ -86,7 +91,7 @@ class Command(BaseCommand):
|
|||
object_count = 0
|
||||
if not schema_only:
|
||||
for model in models:
|
||||
self.stdout.write(
|
||||
self.write(
|
||||
"{}: {}.{} ".format(
|
||||
backend_name, model._meta.app_label, model.__name__
|
||||
).ljust(35),
|
||||
|
@ -107,7 +112,7 @@ class Command(BaseCommand):
|
|||
# Finish rebuild
|
||||
rebuilder.finish()
|
||||
|
||||
self.stdout.write(backend_name + ": indexed %d objects" % object_count)
|
||||
self.write(backend_name + ": indexed %d objects" % object_count)
|
||||
self.print_newline()
|
||||
|
||||
def add_arguments(self, parser):
|
||||
|
@ -135,6 +140,8 @@ class Command(BaseCommand):
|
|||
)
|
||||
|
||||
def handle(self, **options):
|
||||
self.verbosity = options["verbosity"]
|
||||
|
||||
# Get list of backends to index
|
||||
if options["backend_name"]:
|
||||
# index only the passed backend
|
||||
|
@ -155,7 +162,7 @@ class Command(BaseCommand):
|
|||
)
|
||||
|
||||
def print_newline(self):
|
||||
self.stdout.write("")
|
||||
self.write("")
|
||||
|
||||
def print_iter_progress(self, iterable):
|
||||
"""
|
||||
|
@ -170,13 +177,13 @@ class Command(BaseCommand):
|
|||
"""
|
||||
for i, value in enumerate(iterable, start=1):
|
||||
yield value
|
||||
self.stdout.write(".", ending="")
|
||||
self.write(".", ending="")
|
||||
if i % 40 == 0:
|
||||
self.print_newline()
|
||||
self.stdout.write(" " * 35, ending="")
|
||||
self.write(" " * 35, ending="")
|
||||
|
||||
elif i % 10 == 0:
|
||||
self.stdout.write(" ", ending="")
|
||||
self.write(" ", ending="")
|
||||
|
||||
self.stdout.flush()
|
||||
|
||||
|
|
|
@ -906,6 +906,13 @@ class BackendTests(WagtailTestUtils):
|
|||
)
|
||||
self.assertSetEqual({r.title for r in results}, {"Programming Rust"})
|
||||
|
||||
def test_update_index_no_verbosity(self):
|
||||
stdout = StringIO()
|
||||
management.call_command(
|
||||
"update_index", verbosity=0, backend_name=self.backend_name, stdout=stdout
|
||||
)
|
||||
self.assertFalse(stdout.read())
|
||||
|
||||
|
||||
@override_settings(
|
||||
WAGTAILSEARCH_BACKENDS={"default": {"BACKEND": "wagtail.search.backends.database"}}
|
||||
|
|
Ładowanie…
Reference in New Issue