perf: negative website redirect caching (#29179)

This commit is contained in:
Ankush Menat 2025-01-15 14:21:56 +05:30 committed by GitHub
parent d6386e6e06
commit 584727f5e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -114,6 +114,18 @@ def resolve_redirect(path, query_string=None):
# use r as a string prefix if you use regex groups or want to escape any string literal
]
"""
redirect_to = frappe.cache.hget("website_redirects", path)
if redirect_to:
if isinstance(redirect_to, dict):
frappe.flags.redirect_location = redirect_to["path"]
raise frappe.Redirect(redirect_to["status_code"])
frappe.flags.redirect_location = redirect_to
raise frappe.Redirect
if redirect_to is False:
return
redirects = frappe.get_hooks("website_redirects")
redirects += frappe.get_all(
"Website Route Redirect", ["source", "target", "redirect_http_status"], order_by=None
@ -122,15 +134,6 @@ def resolve_redirect(path, query_string=None):
if not redirects:
return
redirect_to = frappe.cache.hget("website_redirects", path)
if redirect_to:
if isinstance(redirect_to, dict):
frappe.flags.redirect_location = redirect_to["path"]
raise frappe.Redirect(redirect_to["status_code"])
frappe.flags.redirect_location = redirect_to
raise frappe.Redirect
for rule in redirects:
pattern = rule["source"].strip("/ ") + "$"
path_to_match = path
@ -151,6 +154,8 @@ def resolve_redirect(path, query_string=None):
)
raise frappe.Redirect(status_code)
frappe.cache.hset("website_redirects", path_to_match, False)
def resolve_path(path):
if not path: