From b6ac46c95488fdc39e6d3c37847b5aa1427c3b72 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Mon, 14 Oct 2024 22:09:22 +0900 Subject: [PATCH] refactor: apply hint for performance Signed-off-by: Jongmin Kim --- .../cost_analysis/service/job_service.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/spaceone/cost_analysis/service/job_service.py b/src/spaceone/cost_analysis/service/job_service.py index eb58080..907ce98 100644 --- a/src/spaceone/cost_analysis/service/job_service.py +++ b/src/spaceone/cost_analysis/service/job_service.py @@ -319,9 +319,6 @@ def get_cost_data(self, params): job_id, data_source_id, domain_id, - data_source_vo.cost_data_keys, - data_source_vo.cost_additional_info_keys, - data_source_vo.cost_tag_keys, job_task_vo.workspace_id, ) @@ -628,9 +625,6 @@ def _close_job( job_id: str, data_source_id: str, domain_id: str, - data_keys: list, - additional_info_keys: list, - tag_keys: list, workspace_id: str = None, ) -> None: job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id) @@ -639,10 +633,6 @@ def _close_job( if job_vo.remained_tasks == 0: if job_vo.status == "IN_PROGRESS": try: - # self._aggregate_cost_data( - # job_vo, data_keys, additional_info_keys, tag_keys - # ) - for changed_vo in job_vo.changed: self._delete_changed_cost_data( job_vo, @@ -765,7 +755,8 @@ def _delete_old_cost_data(self, data_source_id: str, domain_id: str): {"k": "billed_month", "v": old_billed_month, "o": "lt"}, {"k": "data_source_id", "v": data_source_id, "o": "eq"}, {"k": "domain_id", "v": domain_id, "o": "eq"}, - ] + ], + "hint": "COMPOUND_INDEX_FOR_SYNC_JOB_2", } cost_vos, total_count = self.cost_mgr.list_costs( @@ -779,7 +770,8 @@ def _delete_old_cost_data(self, data_source_id: str, domain_id: str): {"k": "billed_year", "v": old_billed_year, "o": "lt"}, {"k": "data_source_id", "v": data_source_id, "o": "eq"}, {"k": "domain_id", "v": domain_id, "o": "eq"}, - ] + ], + "hint": "COMPOUND_INDEX_FOR_SEARCH_2", } monthly_cost_vos, total_count = self.cost_mgr.list_monthly_costs( @@ -799,7 +791,8 @@ def _delete_changed_cost_data( {"k": "data_source_id", "v": job_vo.data_source_id, "o": "eq"}, {"k": "domain_id", "v": job_vo.domain_id, "o": "eq"}, {"k": "job_id", "v": job_vo.job_id, "o": "not"}, - ] + ], + "hint": "COMPOUND_INDEX_FOR_SYNC_JOB_2", } if end: @@ -818,6 +811,7 @@ def _delete_changed_cost_data( f"[_delete_changed_cost_data] delete costs (count = {total_count})" ) + query["hint"] = "COMPOUND_INDEX_FOR_SYNC_JOB" monthly_cost_vos, total_count = self.cost_mgr.list_monthly_costs( copy.deepcopy(query), domain_id )