mirror of
https://github.com/Xevion/xevion.dev.git
synced 2026-01-31 00:26:31 -06:00
refactor: simplify ISR cache invalidation to homepage only
This commit is contained in:
+7
-8
@@ -261,8 +261,8 @@ mod tests {
|
||||
fn test_is_cacheable_path() {
|
||||
// Should cache
|
||||
assert!(is_cacheable_path("/"));
|
||||
assert!(is_cacheable_path("/projects"));
|
||||
assert!(is_cacheable_path("/projects/my-project"));
|
||||
assert!(is_cacheable_path("/some-page"));
|
||||
assert!(is_cacheable_path("/pgp"));
|
||||
|
||||
// Should not cache
|
||||
assert!(!is_cacheable_path("/admin"));
|
||||
@@ -274,12 +274,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_cache_key() {
|
||||
assert_eq!(cache_key("/projects", None), "/projects");
|
||||
assert_eq!(cache_key("/projects", Some("")), "/projects");
|
||||
assert_eq!(
|
||||
cache_key("/projects", Some("tag=rust")),
|
||||
"/projects?tag=rust"
|
||||
);
|
||||
assert_eq!(cache_key("/", None), "/");
|
||||
assert_eq!(cache_key("/", Some("")), "/");
|
||||
assert_eq!(cache_key("/", Some("tag=rust")), "/?tag=rust");
|
||||
assert_eq!(cache_key("/", Some("utm_source=x")), "/?utm_source=x");
|
||||
assert_eq!(cache_key("/some-page", None), "/some-page");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -244,7 +244,7 @@ pub async fn create_project_handler(
|
||||
tracing::info!(project_id = %project.id, project_name = %project.name, "Project created");
|
||||
|
||||
// Invalidate cached pages that display projects
|
||||
state.isr_cache.invalidate_many(&["/", "/projects"]).await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
@@ -414,12 +414,7 @@ pub async fn update_project_handler(
|
||||
tracing::info!(project_id = %project.id, project_name = %project.name, "Project updated");
|
||||
|
||||
// Invalidate cached pages that display projects
|
||||
// Also invalidate slug-based path in case project detail pages exist
|
||||
let project_path = format!("/projects/{}", project.slug);
|
||||
state
|
||||
.isr_cache
|
||||
.invalidate_many(&["/", "/projects", &project_path])
|
||||
.await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
Json(project.to_api_admin_project(tags)).into_response()
|
||||
}
|
||||
@@ -482,11 +477,7 @@ pub async fn delete_project_handler(
|
||||
tracing::info!(project_id = %project_id, project_name = %project.name, "Project deleted");
|
||||
|
||||
// Invalidate cached pages that display projects
|
||||
let project_path = format!("/projects/{}", project.slug);
|
||||
state
|
||||
.isr_cache
|
||||
.invalidate_many(&["/", "/projects", &project_path])
|
||||
.await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
Json(project.to_api_admin_project(tags)).into_response()
|
||||
}
|
||||
@@ -609,7 +600,7 @@ pub async fn add_project_tag_handler(
|
||||
match db::add_tag_to_project(&state.pool, project_id, tag_id).await {
|
||||
Ok(()) => {
|
||||
// Invalidate cached pages - tags affect how projects are displayed
|
||||
state.isr_cache.invalidate_many(&["/", "/projects"]).await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
@@ -681,7 +672,7 @@ pub async fn remove_project_tag_handler(
|
||||
match db::remove_tag_from_project(&state.pool, project_id, tag_id).await {
|
||||
Ok(()) => {
|
||||
// Invalidate cached pages - tags affect how projects are displayed
|
||||
state.isr_cache.invalidate_many(&["/", "/projects"]).await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
|
||||
@@ -80,7 +80,7 @@ pub async fn create_tag_handler(
|
||||
{
|
||||
Ok(tag) => {
|
||||
// Invalidate cached pages - tag list appears on project pages
|
||||
state.isr_cache.invalidate_many(&["/", "/projects"]).await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
(StatusCode::CREATED, Json(tag.to_api_tag())).into_response()
|
||||
}
|
||||
@@ -226,7 +226,7 @@ pub async fn update_tag_handler(
|
||||
{
|
||||
Ok(updated_tag) => {
|
||||
// Invalidate cached pages - tag updates affect project displays
|
||||
state.isr_cache.invalidate_many(&["/", "/projects"]).await;
|
||||
state.isr_cache.invalidate("/").await;
|
||||
|
||||
Json(updated_tag.to_api_tag()).into_response()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user