fix: Use separate API to insert route history
This commit is contained in:
parent
4cae147aed
commit
0e32d52e3a
3 changed files with 26 additions and 7 deletions
|
|
@ -5,7 +5,6 @@ from frappe.utils import cstr
|
|||
|
||||
queue_prefix = 'insert_queue_for_'
|
||||
|
||||
@frappe.whitelist()
|
||||
def deferred_insert(doctype, records):
|
||||
frappe.cache().rpush(queue_prefix + doctype, records)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
# Copyright (c) 2021, Frappe Technologies and contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
import json
|
||||
|
||||
import frappe
|
||||
from frappe.deferred_insert import deferred_insert
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class RouteHistory(Document):
|
||||
pass
|
||||
|
||||
|
|
@ -35,3 +39,19 @@ def flush_old_route_records():
|
|||
"modified": ("<=", last_record_to_keep[0].modified),
|
||||
"user": user
|
||||
})
|
||||
|
||||
@frappe.whitelist()
|
||||
def deferred_insert_route_history(routes):
|
||||
routes_record = []
|
||||
|
||||
if isinstance(routes, str):
|
||||
routes = json.loads(routes)
|
||||
|
||||
for route_doc in routes:
|
||||
routes_record.append({
|
||||
"user": frappe.session.user,
|
||||
"route": route_doc.get("route"),
|
||||
"creation": route_doc.get("creation")
|
||||
})
|
||||
|
||||
deferred_insert("Route History", json.dumps(routes_record))
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ const save_routes = frappe.utils.debounce(() => {
|
|||
if (frappe.session.user === 'Guest') return;
|
||||
const routes = frappe.route_history_queue;
|
||||
frappe.route_history_queue = [];
|
||||
|
||||
frappe.xcall('frappe.deferred_insert.deferred_insert', {
|
||||
'doctype': 'Route History',
|
||||
'records': routes
|
||||
|
||||
if (!routes.length) return;
|
||||
|
||||
frappe.xcall('frappe.desk.doctype.route_history.route_history.deferred_insert_route_history', {
|
||||
'routes': routes
|
||||
}).catch(() => {
|
||||
frappe.route_history_queue.concat(routes);
|
||||
});
|
||||
});
|
||||
|
||||
}, 10000);
|
||||
|
||||
|
|
@ -19,7 +20,6 @@ frappe.router.on('change', () => {
|
|||
const route = frappe.get_route();
|
||||
if (is_route_useful(route)) {
|
||||
frappe.route_history_queue.push({
|
||||
'user': frappe.session.user,
|
||||
'creation': frappe.datetime.now_datetime(),
|
||||
'route': frappe.get_route_str()
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue