Skip to content

Commit 6854235

Browse files
committed
fix: refresh and parallel option of the CLI now use the settings as default
1 parent f8dffdd commit 6854235

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

django_opensearch_dsl/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def auto_refresh_enabled(cls):
3535
"""Return whether auto refresh is enabled."""
3636
return getattr(settings, "OPENSEARCH_DSL_AUTO_REFRESH", False)
3737

38+
@classmethod
39+
def parallel_enabled(cls):
40+
"""Return whether parallel operation is enabled."""
41+
return getattr(settings, "OPENSEARCH_DSL_PARALLEL", False)
42+
3843
@classmethod
3944
def default_queryset_pagination(cls):
4045
"""Return `OPENSEARCH_DSL_QUERYSET_PAGINATION`."""

django_opensearch_dsl/management/commands/opensearch.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from django_opensearch_dsl.registries import registry
1818

19+
from ...apps import DODConfig
1920
from ..enums import OpensearchAction
2021
from ..types import parse
2122

@@ -324,20 +325,30 @@ def add_arguments(self, parser):
324325
subparser.add_argument(
325326
"-c", "--count", type=int, default=None, help="Update at most COUNT objects (0 to index everything)."
326327
)
327-
subparser.add_argument(
328-
"-p",
329-
"--parallel",
330-
action="store_true",
331-
default=False,
332-
help="Parallelize the communication with Opensearch.",
333-
)
334-
subparser.add_argument(
328+
refresh = subparser.add_mutually_exclusive_group()
329+
refresh.add_argument(
335330
"-r",
336331
"--refresh",
337332
action="store_true",
338-
default=False,
339-
help="Make operations performed on the indices immediatly available for search.",
333+
default=DODConfig.auto_refresh_enabled(),
334+
help=(
335+
"Whether the operations performed on the indices are immediately available for search. Default to "
336+
"`OPENSEARCH_DSL_AUTO_REFRESH` (which default to `False`)"
337+
),
338+
)
339+
refresh.add_argument("--no-refresh", action="store_false")
340+
parallel = subparser.add_mutually_exclusive_group()
341+
parallel.add_argument(
342+
"-p",
343+
"--parallel",
344+
action="store_true",
345+
default=DODConfig.parallel_enabled(),
346+
help=(
347+
"Whether to run bulk operations in parallel. Default to `OPENSEARCH_DSL_PARALLEL` (which default to "
348+
"`False`)"
349+
),
340350
)
351+
refresh.add_argument("--no-parallel", action="store_false")
341352
subparser.add_argument(
342353
"-m",
343354
"--missing",

docs/settings.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ an [index refresh](https://www.elastic.co/guide/en/elasticsearch/reference/curre
3939

4040
Default: `False`
4141

42-
Run indexing in parallel using OpenSearch's parallel_bulk() method. Note that some databases (e.g. SQLite)
43-
do not play well with this option.
42+
Run bulk operations in parallel. Note that some databases (e.g. sqlite) do not play well with this option.
4443

4544
## `OPENSEARCH_DSL_QUERYSET_PAGINATION`
4645

tests/tests/management/test_index.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
from django_opensearch_dsl import fields
99
from django_opensearch_dsl.registries import registry
1010

11-
devnull = open(os.devnull, "w")
12-
call_command = functools.partial(call_command, stdout=devnull, stderr=devnull)
13-
1411

1512
class IndexTestCase(SimpleTestCase):
1613

14+
@classmethod
15+
def setUpClass(cls):
16+
super().setUpClass()
17+
devnull = open(os.devnull, "w")
18+
cls.call_command = functools.partial(call_command, stdout=devnull, stderr=devnull)
19+
1720
def setUp(self) -> None:
1821
indices = registry.get_indices()
1922
for i in indices:

0 commit comments

Comments
 (0)