refactor: move flush_local_link_count to hook
This commit is contained in:
parent
ccc107b41f
commit
3f1c66de10
2 changed files with 8 additions and 8 deletions
|
|
@ -987,7 +987,6 @@ class Database:
|
|||
self.after_commit.run()
|
||||
|
||||
self.flush_realtime_log()
|
||||
flush_local_link_count()
|
||||
|
||||
def rollback(self, *, save_point=None):
|
||||
"""`ROLLBACK` current transaction. Optionally rollback to a known save_point."""
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ def notify_link_count(doctype, name):
|
|||
else:
|
||||
frappe.local.link_count[(doctype, name)] = 1
|
||||
|
||||
frappe.db.after_commit.add(flush_local_link_count)
|
||||
|
||||
|
||||
def flush_local_link_count():
|
||||
"""flush from local before ending request"""
|
||||
|
|
@ -31,6 +33,7 @@ def flush_local_link_count():
|
|||
link_count[key] = frappe.local.link_count[key]
|
||||
|
||||
frappe.cache().set_value("_link_count", link_count)
|
||||
frappe.local.link_count = {}
|
||||
|
||||
|
||||
def update_link_count():
|
||||
|
|
@ -38,14 +41,12 @@ def update_link_count():
|
|||
link_count = frappe.cache().get_value("_link_count")
|
||||
|
||||
if link_count:
|
||||
for key, count in link_count.items():
|
||||
if key[0] not in ignore_doctypes:
|
||||
for (doctype, name), count in link_count.items():
|
||||
if doctype not in ignore_doctypes:
|
||||
try:
|
||||
frappe.db.sql(
|
||||
f"update `tab{key[0]}` set idx = idx + {count} where name=%s",
|
||||
key[1],
|
||||
auto_commit=1,
|
||||
)
|
||||
table = frappe.qb.DocType(doctype)
|
||||
frappe.qb.update(table).set(table.idx, table.idx + count).where(table.name == name).run()
|
||||
frappe.db.commit()
|
||||
except Exception as e:
|
||||
if not frappe.db.is_table_missing(e): # table not found, single
|
||||
raise e
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue