perf: cache meta tags existence
This commit is contained in:
parent
dc7636de8f
commit
0ff3e6fd4c
2 changed files with 14 additions and 4 deletions
|
|
@ -20,3 +20,9 @@ class WebsiteRouteMeta(Document):
|
|||
def autoname(self):
|
||||
if self.name and self.name.startswith("/"):
|
||||
self.name = self.name[1:]
|
||||
|
||||
def clear_cache(self):
|
||||
from frappe.website.website_components.metatags import has_meta_tags
|
||||
|
||||
has_meta_tags.clear_cache()
|
||||
return super().clear_cache()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import frappe
|
||||
from frappe.utils.caching import site_cache
|
||||
|
||||
METATAGS = ("title", "description", "image", "author", "published_on")
|
||||
|
||||
|
|
@ -58,14 +59,17 @@ class MetaTags:
|
|||
route = self.path
|
||||
if route == "":
|
||||
# homepage
|
||||
route = frappe.db.get_single_value("Website Settings", "home_page")
|
||||
route = frappe.get_website_settings("home_page")
|
||||
|
||||
route_exists = (
|
||||
route and not route.endswith((".js", ".css")) and frappe.db.exists("Website Route Meta", route)
|
||||
)
|
||||
route_exists = route and not route.endswith((".js", ".css")) and has_meta_tags(route)
|
||||
|
||||
if route_exists:
|
||||
website_route_meta = frappe.get_doc("Website Route Meta", route)
|
||||
for meta_tag in website_route_meta.meta_tags:
|
||||
d = meta_tag.get_meta_dict()
|
||||
self.tags.update(d)
|
||||
|
||||
|
||||
@site_cache(ttl=10 * 60, maxsize=16)
|
||||
def has_meta_tags(route):
|
||||
return bool(frappe.db.exists("Website Route Meta", route))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue