Merge pull request #15114 from surajshetty3416/fix-deferred-insert

fix: Use separate API to insert route history
This commit is contained in:
mergify[bot] 2021-11-29 13:38:17 +00:00 committed by GitHub
commit cb3533556b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -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)

View file

@ -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 as _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(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))

View file

@ -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', {
'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()
});