Skip to content

Commit

Permalink
Merge pull request #297 from whdalsrnt/master
Browse files Browse the repository at this point in the history
refactor: apply hint for performance
  • Loading branch information
whdalsrnt authored Oct 14, 2024
2 parents 3c05436 + b6ac46c commit 20c3977
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -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
)
Expand Down

0 comments on commit 20c3977

Please sign in to comment.