Skip to content

Commit

Permalink
refactor(site): If perf schema disabled, don't try to fetch perf reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Jan 1, 2025
1 parent 1798667 commit a1e9924
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions press/press/doctype/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,6 @@ def get_database_performance_report(self):
from press.press.report.mariadb_slow_queries.mariadb_slow_queries import get_data as get_slow_queries

agent = Agent(self.server)
result = agent.get_summarized_performance_report_of_database(self)
# fetch slow queries of last 7 days
slow_queries = get_slow_queries(
frappe._dict(
Expand All @@ -2334,27 +2333,40 @@ def get_database_performance_report(self):
}
)
)
# remove `parent` & `creation` indexes from unused_indexes
result["unused_indexes"] = [
index
for index in result.get("unused_indexes", [])
if index["index_name"] not in ["parent", "creation"]
]

# convert all the float to int
for query in slow_queries:
for key, value in query.items():
if isinstance(value, float):
query[key] = int(value)
# sort the slow queries by `rows_examined`
result["slow_queries"] = sorted(slow_queries, key=lambda x: x["rows_examined"], reverse=True)
result["is_performance_schema_enabled"] = False
is_performance_schema_enabled = False
if database_server := frappe.db.get_value("Server", self.server, "database_server"):
result["is_performance_schema_enabled"] = frappe.db.get_value(
is_performance_schema_enabled = frappe.db.get_value(
"Database Server",
database_server,
"is_performance_schema_enabled",
)
result = None
if is_performance_schema_enabled:
with suppress(Exception):
# for larger table or if database has any locks, fetching perf report will be failed
result = agent.get_summarized_performance_report_of_database(self)
# remove `parent` & `creation` indexes from unused_indexes
result["unused_indexes"] = [
index
for index in result.get("unused_indexes", [])
if index["index_name"] not in ["parent", "creation"]
]

if not result:
result = {}
result["unused_indexes"] = []
result["redundant_indexes"] = []
result["top_10_time_consuming_queries"] = []
result["top_10_queries_with_full_table_scan"] = []

# sort the slow queries by `rows_examined`
result["slow_queries"] = sorted(slow_queries, key=lambda x: x["rows_examined"], reverse=True)
result["is_performance_schema_enabled"] = is_performance_schema_enabled
return result

@property
Expand Down

0 comments on commit a1e9924

Please sign in to comment.