Skip to content

Commit

Permalink
Merge pull request #153 from whdalsrnt/master
Browse files Browse the repository at this point in the history
Add Query Option
  • Loading branch information
whdalsrnt authored Aug 26, 2024
2 parents 9a10aa9 + 46c082d commit 8d137e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
28 changes: 20 additions & 8 deletions src/spaceone/core/model/mongo_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def _make_aggregate_rules(cls, aggregate):
return _aggregate_rules

@classmethod
def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use):
def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use, return_type):
result = {}
pipeline = []
_aggregate_rules = cls._make_aggregate_rules(aggregate)
Expand Down Expand Up @@ -1148,8 +1148,12 @@ def _stat_aggregate(cls, vos, aggregate, page, allow_disk_use):
cursor = vos.aggregate(pipeline, allowDiskUse=True)
else:
cursor = vos.aggregate(pipeline)
result["results"] = cls._make_aggregate_values(cursor)
return result

if return_type == "cursor":
return cursor
else:
result["results"] = cls._make_aggregate_values(cursor)
return result

@classmethod
def _stat_distinct(cls, vos, distinct, page):
Expand Down Expand Up @@ -1184,6 +1188,7 @@ def stat(
reference_filter=None,
target="SECONDARY_PREFERRED",
allow_disk_use=False,
return_type="dict",
**kwargs,
):
filter = filter or []
Expand All @@ -1199,7 +1204,9 @@ def stat(
vos = cls._get_target_objects(target).filter(_filter)

if aggregate:
return cls._stat_aggregate(vos, aggregate, page, allow_disk_use)
return cls._stat_aggregate(
vos, aggregate, page, allow_disk_use, return_type
)

elif distinct:
return cls._stat_distinct(vos, distinct, page)
Expand Down Expand Up @@ -1499,6 +1506,7 @@ def analyze(
reference_filter=None,
target="SECONDARY_PREFERRED",
allow_disk_use=False,
return_type="dict",
**kwargs,
):
if fields is None:
Expand Down Expand Up @@ -1540,6 +1548,7 @@ def analyze(
"aggregate": aggregate,
"target": target,
"allow_disk_use": allow_disk_use,
"return_type": return_type,
"reference_filter": reference_filter,
}

Expand All @@ -1561,8 +1570,11 @@ def analyze(

response = cls.stat(**query)

if page_limit:
response["more"] = len(response["results"]) > page_limit
response["results"] = response["results"][:page_limit]
if return_type == "cursor":
return response
else:
if page_limit:
response["more"] = len(response["results"]) > page_limit
response["results"] = response["results"][:page_limit]

return response
return response
34 changes: 17 additions & 17 deletions src/spaceone/core/pygrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _generate_response(self, response_iterator):
self._check_error(e)

def _retry_call(
self, continuation, client_call_details, request_or_iterator, is_stream
self, continuation, client_call_details, request_or_iterator, is_stream
):
retries = 0

Expand Down Expand Up @@ -142,12 +142,12 @@ def _retry_call(
retries += 1

def _intercept_call(
self,
continuation,
client_call_details,
request_or_iterator,
is_request_stream,
is_response_stream,
self,
continuation,
client_call_details,
request_or_iterator,
is_request_stream,
is_response_stream,
):
new_request_or_iterator = self._check_message(
client_call_details, request_or_iterator, is_request_stream
Expand All @@ -171,14 +171,14 @@ def intercept_unary_stream(self, continuation, client_call_details, request):
)

def intercept_stream_unary(
self, continuation, client_call_details, request_iterator
self, continuation, client_call_details, request_iterator
):
return self._intercept_call(
continuation, client_call_details, request_iterator, True, False
)

def intercept_stream_stream(
self, continuation, client_call_details, request_iterator
self, continuation, client_call_details, request_iterator
):
return self._intercept_call(
continuation, client_call_details, request_iterator, True, True
Expand All @@ -187,20 +187,20 @@ def intercept_stream_stream(

class _GRPCStub(object):
def __init__(
self,
desc_pool: DescriptorPool,
service_desc: ServiceDescriptor,
channel: grpc.Channel,
self,
desc_pool: DescriptorPool,
service_desc: ServiceDescriptor,
channel: grpc.Channel,
):
self._desc_pool = desc_pool
for method_desc in service_desc.methods:
self._bind_grpc_method(service_desc, method_desc, channel)

def _bind_grpc_method(
self,
service_desc: ServiceDescriptor,
method_desc: MethodDescriptor,
channel: grpc.Channel,
self,
service_desc: ServiceDescriptor,
method_desc: MethodDescriptor,
channel: grpc.Channel,
):
method_name = method_desc.name
method_key = f"/{service_desc.full_name}/{method_name}"
Expand Down

0 comments on commit 8d137e0

Please sign in to comment.