This commit is contained in:
Tomas Dvorak
2025-10-21 15:02:05 +02:00
parent 68e69e00cc
commit 63700eedb2
103 changed files with 12442 additions and 446 deletions
+24 -1
View File
@@ -6,6 +6,7 @@ import (
"fotbal-club/internal/services"
"fotbal-club/pkg/logger"
"net/http"
"os"
"strings"
"time"
@@ -245,9 +246,31 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
// 17. Reload with associations for response
ac.DB.Preload("Author").Preload("Category").First(&article, article.ID)
// 18. Return success response
// 18. Trigger prefetch cache update (async)
if published {
go func() {
base := getBaseURL()
logger.Info("CreateArticle: Triggering prefetch cache update for published article")
services.PrefetchOnce(base)
}()
}
// 19. Return success response
c.JSON(http.StatusCreated, article)
}
// getBaseURL returns the base URL for internal API calls (used for prefetch trigger)
func getBaseURL() string {
base := strings.TrimSpace(os.Getenv("PREFETCH_TARGET"))
if base == "" {
port := strings.TrimSpace(os.Getenv("PORT"))
if port == "" {
port = "8080"
}
base = "http://127.0.0.1:" + port + "/api/v1"
}
return base
}
// Note: Helper functions makeSlug, computeEstimatedReadMinutes, and deriveSeoDescription
// are defined in base_controller.go and shared across the controllers package