[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
This commit is contained in:
Prateeksha Singh 2018-07-24 16:30:17 +05:30 committed by Rushabh Mehta
parent feee6cc07e
commit 0c5f5dcb92

View file

@ -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
return match_filters