ソースを参照

fix: Use separate API to insert route history

version-14
Suraj Shetty 3年前
コミット
0e32d52e3a
3個のファイルの変更26行の追加7行の削除
  1. +0
    -1
      frappe/deferred_insert.py
  2. +20
    -0
      frappe/desk/doctype/route_history/route_history.py
  3. +6
    -6
      frappe/public/js/frappe/router_history.js

+ 0
- 1
frappe/deferred_insert.py ファイルの表示

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



+ 20
- 0
frappe/desk/doctype/route_history/route_history.py ファイルの表示

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

+ 6
- 6
frappe/public/js/frappe/router_history.js ファイルの表示

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


読み込み中…
キャンセル
保存