Merge pull request #9711 from scmmishra/cache-fix
refactor: improve caching for desk
This commit is contained in:
commit
2f24671030
2 changed files with 17 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import frappe, json
|
||||
import frappe.defaults
|
||||
from frappe.model.document import Document
|
||||
from frappe.desk.notifications import (delete_notification_count_for,
|
||||
clear_notifications)
|
||||
|
||||
|
|
@ -22,6 +23,10 @@ user_cache_keys = ("bootinfo", "user_recent", "roles", "user_doc", "lang",
|
|||
doctype_cache_keys = ("meta", "form_meta", "table_columns", "last_modified",
|
||||
"linked_doctypes", 'notifications', 'workflow' ,'energy_point_rule_map')
|
||||
|
||||
count_cache_blacklist = ["Version", "Tag", "ToDo", "List Filter", "Note Seen By", "Notification Log",
|
||||
"Document Follow", "Communication", "Email Queue", "Deleted Document", "File", "Email Queue Recipient"
|
||||
"Comment", "Has Role", "Attendance", "Route History"]
|
||||
|
||||
|
||||
def clear_user_cache(user=None):
|
||||
cache = frappe.cache()
|
||||
|
|
@ -116,13 +121,23 @@ def clear_doctype_map(doctype, name):
|
|||
cache_key = frappe.scrub(doctype) + '_map'
|
||||
frappe.cache().hdel(cache_key, name)
|
||||
|
||||
def build_table_count_cache(*args, **kwargs):
|
||||
def build_table_count_cache(doc=None, method=None, *args, **kwargs):
|
||||
if (frappe.flags.in_patch
|
||||
or frappe.flags.in_install
|
||||
or frappe.flags.in_migrate
|
||||
or frappe.flags.in_import
|
||||
or frappe.flags.in_setup_wizard):
|
||||
return
|
||||
|
||||
if doc and isinstance(doc, Document):
|
||||
doctype = doc.doctype
|
||||
|
||||
if doc.meta.istable:
|
||||
return
|
||||
|
||||
if doctype in count_cache_blacklist:
|
||||
return
|
||||
|
||||
_cache = frappe.cache()
|
||||
data = frappe.db.multisql({
|
||||
"mariadb": """
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Workspace:
|
|||
self.allowed_pages = get_allowed_pages()
|
||||
self.allowed_reports = get_allowed_reports()
|
||||
|
||||
self.table_counts = build_table_count_cache()
|
||||
self.table_counts = get_table_with_counts()
|
||||
self.restricted_doctypes = build_domain_restriced_doctype_cache()
|
||||
self.restricted_pages = build_domain_restriced_page_cache()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue