Merge pull request #24644 from ankush/clear_sitemap_cache
fix: clear sitemap cache periodically
This commit is contained in:
commit
dd6f20b301
2 changed files with 32 additions and 31 deletions
|
|
@ -322,7 +322,9 @@ def clear_routing_cache():
|
|||
from frappe.website.doctype.web_form.web_form import get_published_web_forms
|
||||
from frappe.website.doctype.web_page.web_page import get_dynamic_web_pages
|
||||
from frappe.website.page_renderers.document_page import _find_matching_document_webview
|
||||
from frappe.www.sitemap import get_public_pages_from_doctypes
|
||||
|
||||
_find_matching_document_webview.clear_cache()
|
||||
get_dynamic_web_pages.clear_cache()
|
||||
get_published_web_forms.clear_cache()
|
||||
get_public_pages_from_doctypes.clear_cache()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from urllib.parse import quote
|
|||
import frappe
|
||||
from frappe.model.document import get_controller
|
||||
from frappe.utils import get_url, nowdate
|
||||
from frappe.utils.caching import redis_cache
|
||||
from frappe.website.router import get_pages
|
||||
|
||||
no_cache = 1
|
||||
|
|
@ -31,42 +32,40 @@ def get_context(context):
|
|||
return {"links": links}
|
||||
|
||||
|
||||
@redis_cache(ttl=6 * 60 * 60)
|
||||
def get_public_pages_from_doctypes():
|
||||
"""Return pages from doctypes that are publicly accessible."""
|
||||
|
||||
def get_sitemap_routes():
|
||||
routes = {}
|
||||
doctypes_with_web_view = frappe.get_all(
|
||||
"DocType",
|
||||
filters={"has_web_view": True, "allow_guest_to_view": True},
|
||||
pluck="name",
|
||||
)
|
||||
routes = {}
|
||||
doctypes_with_web_view = frappe.get_all(
|
||||
"DocType",
|
||||
filters={"has_web_view": True, "allow_guest_to_view": True},
|
||||
pluck="name",
|
||||
)
|
||||
|
||||
for doctype in doctypes_with_web_view:
|
||||
controller = get_controller(doctype)
|
||||
meta = frappe.get_meta(doctype)
|
||||
condition_field = meta.is_published_field or controller.website.condition_field
|
||||
for doctype in doctypes_with_web_view:
|
||||
controller = get_controller(doctype)
|
||||
meta = frappe.get_meta(doctype)
|
||||
condition_field = meta.is_published_field or controller.website.condition_field
|
||||
|
||||
if not condition_field:
|
||||
continue
|
||||
if not condition_field:
|
||||
continue
|
||||
|
||||
try:
|
||||
res = frappe.get_all(
|
||||
doctype,
|
||||
fields=["route", "name", "modified"],
|
||||
filters={condition_field: True},
|
||||
)
|
||||
except Exception as e:
|
||||
if not frappe.db.is_missing_column(e):
|
||||
raise e
|
||||
try:
|
||||
res = frappe.get_all(
|
||||
doctype,
|
||||
fields=["route", "name", "modified"],
|
||||
filters={condition_field: True},
|
||||
)
|
||||
except Exception as e:
|
||||
if not frappe.db.is_missing_column(e):
|
||||
raise e
|
||||
|
||||
for r in res:
|
||||
routes[r.route] = {
|
||||
"doctype": doctype,
|
||||
"name": r.name,
|
||||
"modified": r.modified,
|
||||
}
|
||||
for r in res:
|
||||
routes[r.route] = {
|
||||
"doctype": doctype,
|
||||
"name": r.name,
|
||||
"modified": r.modified,
|
||||
}
|
||||
|
||||
return routes
|
||||
|
||||
return frappe.cache.get_value("sitemap_routes", get_sitemap_routes)
|
||||
return routes
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue