Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add json_metadata for performance #336

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/spaceone/inventory/service/cloud_service_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def create_resource(self, params: dict) -> CloudService:
elif "data" not in params:
raise ERROR_REQUIRED_PARAMETER(key="data")

if "json_metadata" in params:
params["metadata"] = utils.load_json(params["json_metadata"])
if not isinstance(params["metadata"], dict):
raise ERROR_INVALID_PARAMETER_TYPE(
key="json_metadata", type=type(params["metadata"])
)

del params["json_metadata"]

domain_id = params["domain_id"]
workspace_id = params["workspace_id"]
secret_project_id = self.transaction.get_meta("secret.project_id")
Expand Down Expand Up @@ -198,9 +207,6 @@ def update_resource(self, params: dict) -> CloudService:
ch_mgr: ChangeHistoryManager = self.locator.get_manager("ChangeHistoryManager")

if "json_data" in params:
_LOGGER.debug(
f"[update_resource] load json_data: {params['cloud_service_id']}"
)
params["data"] = utils.load_json(params["json_data"])
if not isinstance(params["data"], dict):
raise ERROR_INVALID_PARAMETER_TYPE(
Expand All @@ -209,6 +215,15 @@ def update_resource(self, params: dict) -> CloudService:

del params["json_data"]

if "json_metadata" in params:
params["metadata"] = utils.load_json(params["json_metadata"])
if not isinstance(params["metadata"], dict):
raise ERROR_INVALID_PARAMETER_TYPE(
key="json_metadata", type=type(params["metadata"])
)

del params["json_metadata"]

secret_project_id = self.transaction.get_meta("secret.project_id")

cloud_service_id = params["cloud_service_id"]
Expand Down Expand Up @@ -281,7 +296,6 @@ def update_resource(self, params: dict) -> CloudService:

params = self.cloud_svc_mgr.merge_data(params, old_cloud_svc_data)

_LOGGER.debug(f"[update_resource] merged params: {params}")
cloud_svc_vo = self.cloud_svc_mgr.update_cloud_service_by_vo(
params, cloud_svc_vo
)
Expand Down
Loading