perf: Simplify code to avoid unnecessary DB calls
This commit is contained in:
parent
af287a04a9
commit
f7db085db5
2 changed files with 8 additions and 6 deletions
|
|
@ -13,5 +13,6 @@ class DocumentShareKey(Document):
|
|||
None, days=frappe.get_system_settings("document_share_key_expiry") or 90
|
||||
)
|
||||
|
||||
def is_expired(self):
|
||||
return self.expires_on and self.expires_on < frappe.utils.getdate()
|
||||
|
||||
def is_expired(expires_on):
|
||||
return expires_on and expires_on < frappe.utils.getdate()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import re
|
|||
import frappe
|
||||
from frappe import _, get_module_path
|
||||
from frappe.core.doctype.access_log.access_log import make_access_log
|
||||
from frappe.core.doctype.document_share_key.document_share_key import is_expired
|
||||
from frappe.utils import cint, sanitize_html, strip_html
|
||||
from frappe.utils.jinja_globals import is_rtl
|
||||
|
||||
|
|
@ -344,13 +345,13 @@ def validate_print_permission(doc):
|
|||
|
||||
|
||||
def validate_key(key, doc):
|
||||
document_share_key = frappe.db.exists(
|
||||
document_key_expiry = frappe.get_cached_value(
|
||||
"Document Share Key",
|
||||
{"reference_doctype": doc.doctype, "reference_docname": doc.name, "key": key},
|
||||
cache=True,
|
||||
["expires_on"],
|
||||
)
|
||||
if document_share_key:
|
||||
if frappe.get_cached_doc("Document Share Key", document_share_key).is_expired():
|
||||
if document_key_expiry is not None:
|
||||
if is_expired(document_key_expiry[0]):
|
||||
raise frappe.exceptions.LinkExpiredError
|
||||
else:
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue