From 0c5f5dcb928f8cbc06dff6f1f205441db88360c5 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 24 Jul 2018 16:30:17 +0530 Subject: [PATCH] [prepared-report] see if report took more than 10 seconds (#5864) * [prepared-report] see if report took more than 10 seconds * Update query_report.py * Update query_report.py --- frappe/desk/query_report.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index 3f6bad7d6e..843e3d5d26 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe -import os, json +import os, json, datetime from frappe import _ from frappe.modules import scrub, get_module_path @@ -16,7 +16,6 @@ from frappe.utils.csvutils import read_csv_content_from_attached_file from frappe.permissions import get_role_permissions from six import string_types, iteritems - def get_report_doc(report_name): doc = frappe.get_doc("Report", report_name) if not doc.is_permitted(): @@ -57,11 +56,17 @@ def generate_report_result(report, filters=None, user=None): module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module") if report.is_standard == "Yes": method_name = get_report_module_dotted_path(module, report.name) + ".execute" - + threshold = 10 res = [] - + + start_time = datetime.datetime.now() # The JOB res = frappe.get_attr(method_name)(frappe._dict(filters)) + + end_time = datetime.datetime.now() + + if (end_time - start_time).seconds > threshold and not report.prepared_report: + report.db_set('prepared', 1) columns, result = res[0], res[1] if len(res) > 2: @@ -86,7 +91,6 @@ def generate_report_result(report, filters=None, user=None): "status": status } - @frappe.whitelist() def background_enqueue_run(report_name, filters=None, user=None): """run reports in background""" @@ -468,4 +472,4 @@ def get_user_match_filters(doctypes, user): if filter_list: match_filters[dt] = filter_list - return match_filters \ No newline at end of file + return match_filters