feat: invalidate sitemap cache on article publish/delete/create
Add invalidate_sitemap_cache() to sitemap.py and call it from article_publish, article_delete, and article_new admin routes. Subtask 6 of CMS admin improvement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1740,6 +1740,9 @@ async def article_new():
|
|||||||
(url_path, article_slug, title, meta_description, og_image_url,
|
(url_path, article_slug, title, meta_description, og_image_url,
|
||||||
country, region, status, pub_dt),
|
country, region, status, pub_dt),
|
||||||
)
|
)
|
||||||
|
from ..sitemap import invalidate_sitemap_cache
|
||||||
|
invalidate_sitemap_cache()
|
||||||
|
|
||||||
await flash(f"Article '{title}' created.", "success")
|
await flash(f"Article '{title}' created.", "success")
|
||||||
return redirect(url_for("admin.articles"))
|
return redirect(url_for("admin.articles"))
|
||||||
|
|
||||||
@@ -1828,6 +1831,10 @@ async def article_delete(article_id: int):
|
|||||||
md_path.unlink()
|
md_path.unlink()
|
||||||
|
|
||||||
await execute("DELETE FROM articles WHERE id = ?", (article_id,))
|
await execute("DELETE FROM articles WHERE id = ?", (article_id,))
|
||||||
|
|
||||||
|
from ..sitemap import invalidate_sitemap_cache
|
||||||
|
invalidate_sitemap_cache()
|
||||||
|
|
||||||
await flash("Article deleted.", "success")
|
await flash("Article deleted.", "success")
|
||||||
return redirect(url_for("admin.articles"))
|
return redirect(url_for("admin.articles"))
|
||||||
|
|
||||||
@@ -1848,6 +1855,10 @@ async def article_publish(article_id: int):
|
|||||||
"UPDATE articles SET status = ?, updated_at = ? WHERE id = ?",
|
"UPDATE articles SET status = ?, updated_at = ? WHERE id = ?",
|
||||||
(new_status, now, article_id),
|
(new_status, now, article_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from ..sitemap import invalidate_sitemap_cache
|
||||||
|
invalidate_sitemap_cache()
|
||||||
|
|
||||||
await flash(f"Article status changed to {new_status}.", "success")
|
await flash(f"Article status changed to {new_status}.", "success")
|
||||||
return redirect(url_for("admin.articles"))
|
return redirect(url_for("admin.articles"))
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,13 @@ async def _generate_sitemap_xml(base_url: str) -> str:
|
|||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
|
||||||
|
def invalidate_sitemap_cache() -> None:
|
||||||
|
"""Force sitemap regeneration on next request."""
|
||||||
|
global _cache_xml, _cache_timestamp # noqa: PLW0603
|
||||||
|
_cache_xml = ""
|
||||||
|
_cache_timestamp = 0.0
|
||||||
|
|
||||||
|
|
||||||
async def sitemap_response(base_url: str) -> Response:
|
async def sitemap_response(base_url: str) -> Response:
|
||||||
"""Return cached sitemap XML, regenerating if stale (1-hour TTL)."""
|
"""Return cached sitemap XML, regenerating if stale (1-hour TTL)."""
|
||||||
global _cache_xml, _cache_timestamp # noqa: PLW0603
|
global _cache_xml, _cache_timestamp # noqa: PLW0603
|
||||||
|
|||||||
Reference in New Issue
Block a user