From 2bb52ef116846702d27729e6f8b80341cd4efa04 Mon Sep 17 00:00:00 2001 From: sibikumarkuppusamy Date: Thu, 26 Dec 2024 15:52:45 +0530 Subject: [PATCH] feat: update v15 dec 19 and 20 --- frappe/build.py | 2 +- .../core/doctype/prepared_report/prepared_report.json | 10 +++++++++- frappe/core/doctype/prepared_report/prepared_report.py | 4 ++++ frappe/website/utils.py | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frappe/build.py b/frappe/build.py index fe3878800459..3599d954e1fb 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -197,7 +197,7 @@ def symlink(target, link_name, overwrite=False): if os.path.isdir(link_name): raise IsADirectoryError(f"Cannot symlink over existing directory: '{link_name}'") try: - os.replace(temp_link_name, link_name) + shutil.move(temp_link_name, link_name) except AttributeError: os.renames(temp_link_name, link_name) except Exception: diff --git a/frappe/core/doctype/prepared_report/prepared_report.json b/frappe/core/doctype/prepared_report/prepared_report.json index ec86237d7fbc..0312c17f7ca0 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.json +++ b/frappe/core/doctype/prepared_report/prepared_report.json @@ -13,6 +13,7 @@ "column_break_4", "queued_at", "report_end_time", + "peak_memory_usage", "section_break_7", "error_message", "filters_sb", @@ -101,11 +102,18 @@ "is_virtual": 1, "label": "Queued At", "read_only": 1 + }, + { + "fieldname": "peak_memory_usage", + "fieldtype": "Int", + "label": "Peak Memory Usage", + "print_hide": 1, + "read_only": 1 } ], "in_create": 1, "links": [], - "modified": "2024-03-07 12:01:58.209879", + "modified": "2024-12-20 10:18:19.174608", "modified_by": "Administrator", "module": "Core", "name": "Prepared Report", diff --git a/frappe/core/doctype/prepared_report/prepared_report.py b/frappe/core/doctype/prepared_report/prepared_report.py index 1834fe8cf903..6610221c1776 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.py +++ b/frappe/core/doctype/prepared_report/prepared_report.py @@ -2,6 +2,7 @@ # License: MIT. See LICENSE import gzip import json +import resource from contextlib import suppress from typing import Any @@ -33,6 +34,7 @@ class PreparedReport(Document): error_message: DF.Text | None filters: DF.SmallText | None job_id: DF.Data | None + peak_memory_usage: DF.Int queued_at: DF.Datetime | None queued_by: DF.Data | None report_end_time: DF.Datetime | None @@ -119,6 +121,8 @@ def generate_report(prepared_report): _save_error(instance, error=frappe.get_traceback(with_context=True)) instance.report_end_time = frappe.utils.now() + instance.peak_memory_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + add_data_to_monitor(peak_memory_usage=instance.peak_memory_usage) instance.save(ignore_permissions=True) frappe.publish_realtime( diff --git a/frappe/website/utils.py b/frappe/website/utils.py index ff764ec9dcdf..17272d6c536b 100644 --- a/frappe/website/utils.py +++ b/frappe/website/utils.py @@ -545,14 +545,14 @@ def build_response(path, data, http_status_code, headers: dict | None = None): response = Response() response.data = set_content_type(response, data, path) response.status_code = http_status_code - response.headers["X-Page-Name"] = cstr(path.encode("ascii", errors="xmlcharrefreplace")) + response.headers["X-Page-Name"] = cstr(cstr(path).encode("ascii", errors="xmlcharrefreplace")) response.headers["X-From-Cache"] = frappe.local.response.from_cache or False add_preload_for_bundled_assets(response) if headers: for key, val in headers.items(): - response.headers[key] = cstr(val.encode("ascii", errors="xmlcharrefreplace")) + response.headers[key] = cstr(cstr(val).encode("ascii", errors="xmlcharrefreplace") return response