Skip to content

Commit 6ab5f11

Browse files
author
Jongmin Kim
committed
feat: apply hint option to query
Signed-off-by: Jongmin Kim <whdalsrnt@megazone.com>
1 parent 8d137e0 commit 6ab5f11

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/spaceone/core/model/mongo_model/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ def query(
679679
unwind=None,
680680
reference_filter=None,
681681
target=None,
682+
hint=None,
682683
**kwargs,
683684
):
684685
filter = filter or []
@@ -706,6 +707,9 @@ def query(
706707
try:
707708
vos = cls._get_target_objects(target).filter(_filter)
708709

710+
if hint:
711+
vos = vos.hint(hint)
712+
709713
if len(_order_by) > 0:
710714
vos = vos.order_by(*_order_by)
711715

@@ -1119,7 +1123,7 @@ def _make_aggregate_rules(cls, aggregate):
11191123
return _aggregate_rules
11201124

11211125
@classmethod
1122-
def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use, return_type):
1126+
def _stat_aggregate(cls, vos, aggregate, page, hint, allow_disk_use, return_type):
11231127
result = {}
11241128
pipeline = []
11251129
_aggregate_rules = cls._make_aggregate_rules(aggregate)
@@ -1145,9 +1149,16 @@ def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use, return_type):
11451149

11461150
if allow_disk_use:
11471151
_LOGGER.debug(f"[_stat_aggregate] allow_disk_use: {allow_disk_use}")
1148-
cursor = vos.aggregate(pipeline, allowDiskUse=True)
1152+
1153+
if hint:
1154+
cursor = vos.aggregate(pipeline, hint=hint, allowDiskUse=True)
1155+
else:
1156+
cursor = vos.aggregate(pipeline, allowDiskUse=True)
11491157
else:
1150-
cursor = vos.aggregate(pipeline)
1158+
if hint:
1159+
cursor = vos.aggregate(pipeline, hint=hint)
1160+
else:
1161+
cursor = vos.aggregate(pipeline)
11511162

11521163
if return_type == "cursor":
11531164
return cursor
@@ -1158,6 +1169,7 @@ def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use, return_type):
11581169
@classmethod
11591170
def _stat_distinct(cls, vos, distinct, page):
11601171
result = {}
1172+
11611173
values = vos.distinct(distinct)
11621174

11631175
try:
@@ -1187,6 +1199,7 @@ def stat(
11871199
page=None,
11881200
reference_filter=None,
11891201
target="SECONDARY_PREFERRED",
1202+
hint=None,
11901203
allow_disk_use=False,
11911204
return_type="dict",
11921205
**kwargs,
@@ -1205,7 +1218,7 @@ def stat(
12051218

12061219
if aggregate:
12071220
return cls._stat_aggregate(
1208-
vos, aggregate, page, allow_disk_use, return_type
1221+
vos, aggregate, page, hint, allow_disk_use, return_type
12091222
)
12101223

12111224
elif distinct:

0 commit comments

Comments
 (0)