From ae0edd85fe42162e4810aa5abf7f5181c88e8125 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 17 Jun 2023 20:32:13 +0530 Subject: [PATCH 1/2] perf: Faster report exporting logic (#21415) * perf: Faster report exports to Excel Try exporting report with 100K rows, most likely it fails or takes a really long time. Root causes: - visible_idx was a list, lookups are SLOW AF when lists grow to 100k+ - visible_idx check is not required when I am exporting entire report. Test with 85,000 rows. | | Before | After | Improvement | | --- | --- | --- | --- | | Export | 25.99 | 0.77 | ~33x faster | --- frappe/desk/query_report.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index 5b7c450ae9..3d54520356 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -349,6 +349,13 @@ def build_xlsx_data(data, visible_idx, include_indentation, ignore_visible_idx=F datetime.timedelta, ) + if len(visible_idx) == len(data.result): + # It's not possible to have same length and different content. + ignore_visible_idx = True + else: + # Note: converted for faster lookups + visible_idx = set(visible_idx) + result = [[]] column_widths = [] From 62a3a70bf8d81445648928003f335e532e92ad7c Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sun, 18 Jun 2023 11:23:03 -0400 Subject: [PATCH 2/2] feat: webhook timeout (#21410) * feat: webhook timeout * fix: ensure default timeout 5 seconds Co-authored-by: Ankush Menat --- frappe/integrations/doctype/webhook/webhook.json | 11 ++++++++++- frappe/integrations/doctype/webhook/webhook.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frappe/integrations/doctype/webhook/webhook.json b/frappe/integrations/doctype/webhook/webhook.json index 404e0be944..1728da97d7 100644 --- a/frappe/integrations/doctype/webhook/webhook.json +++ b/frappe/integrations/doctype/webhook/webhook.json @@ -17,6 +17,7 @@ "html_condition", "sb_webhook", "request_url", + "timeout", "is_dynamic_url", "cb_webhook", "request_method", @@ -204,6 +205,14 @@ "fieldname": "is_dynamic_url", "fieldtype": "Check", "label": "Is Dynamic URL?" + }, + { + "default": "5", + "description": "The number of seconds until the request expires", + "fieldname": "timeout", + "fieldtype": "Int", + "label": "Request Timeout", + "reqd": 1 } ], "links": [ @@ -212,7 +221,7 @@ "link_fieldname": "webhook" } ], - "modified": "2023-06-02 17:25:12.598232", + "modified": "2023-06-16 10:21:00.971833", "modified_by": "Administrator", "module": "Integrations", "name": "Webhook", diff --git a/frappe/integrations/doctype/webhook/webhook.py b/frappe/integrations/doctype/webhook/webhook.py index a4d198a118..6fa24bfb67 100644 --- a/frappe/integrations/doctype/webhook/webhook.py +++ b/frappe/integrations/doctype/webhook/webhook.py @@ -129,7 +129,7 @@ def enqueue_webhook(doc, webhook) -> None: url=request_url, data=json.dumps(data, default=str), headers=headers, - timeout=5, + timeout=webhook.timeout or 5, ) r.raise_for_status() frappe.logger().debug({"webhook_success": r.text})