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: apply hint for performance #297

Merged
merged 1 commit into from
Oct 14, 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
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
Loading