refactor(recorder): Use recorder_start and recorder_stop hooks
This commit is contained in:
parent
be6f1a638b
commit
4594836731
2 changed files with 19 additions and 10 deletions
|
|
@ -25,7 +25,7 @@ from frappe.middlewares import RecorderMiddleware, StaticDataMiddleware
|
|||
from frappe.utils.error import make_error_snapshot
|
||||
from frappe.core.doctype.comment.comment import update_comments_in_parent_after_request
|
||||
from frappe import _
|
||||
from frappe.recorder import persist, persist_cache, recorder, wrap_cache
|
||||
from frappe.recorder import recorder_start, recorder_stop
|
||||
|
||||
local_manager = LocalManager([frappe.local])
|
||||
|
||||
|
|
@ -52,11 +52,7 @@ def application(request):
|
|||
|
||||
init_request(request)
|
||||
|
||||
# Need to record all calls to frappe.db.sql
|
||||
# Should be done after frappe.db refers to an instance of Database
|
||||
# Now is a good time
|
||||
wrap_cache()
|
||||
frappe.db.sql = recorder(frappe.db.sql)
|
||||
recorder_start()
|
||||
|
||||
if frappe.local.form_dict.cmd:
|
||||
response = frappe.handler.handle()
|
||||
|
|
@ -98,10 +94,7 @@ def application(request):
|
|||
if response and hasattr(frappe.local, 'cookie_manager'):
|
||||
frappe.local.cookie_manager.flush_cookies(response=response)
|
||||
|
||||
# Recorded calls need to be stored in cache
|
||||
# This looks like a terribe syntax, Because it actually is
|
||||
persist_cache()
|
||||
persist(frappe.db.sql)
|
||||
recorder_stop()
|
||||
frappe.destroy()
|
||||
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -7,6 +7,22 @@ import json
|
|||
import time
|
||||
import frappe
|
||||
|
||||
def recorder_start():
|
||||
# Need to record all calls to frappe.db.sql
|
||||
# Should be done after frappe.db refers to an instance of Database
|
||||
# Now is a good time
|
||||
# If uuid is not set then RecorderMiddleware isn't active
|
||||
if "uuid" in frappe.request.environ:
|
||||
wrap_cache()
|
||||
frappe.db.sql = recorder(frappe.db.sql)
|
||||
|
||||
def recorder_stop():
|
||||
# Recorded calls need to be stored in cache
|
||||
# This looks like a terribe syntax, Because it actually is
|
||||
if "uuid" in frappe.request.environ:
|
||||
persist_cache()
|
||||
persist(frappe.db.sql)
|
||||
|
||||
def time_ms():
|
||||
return time.time() * 1000
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue