mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
finally please
This commit is contained in:
@@ -1913,78 +1913,69 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
// Trigger background prefetch and YouTube cache refresh when settings are updated post-setup
|
||||
scheme := "http"
|
||||
if c.Request.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
host := c.Request.Host
|
||||
if host != "" {
|
||||
baseURL := scheme + "://" + host + "/api/v1"
|
||||
// Best-effort: immediately write public settings cache from current Settings
|
||||
go func(snap models.Settings) {
|
||||
defer func() { _ = recover() }()
|
||||
snap.LoadCustomNav()
|
||||
var pubVids []string
|
||||
if snap.VideosJSON != "" { _ = json.Unmarshal([]byte(snap.VideosJSON), &pubVids) }
|
||||
var pubVidsItems any
|
||||
if snap.VideosItemsJSON != "" { _ = json.Unmarshal([]byte(snap.VideosItemsJSON), &pubVidsItems) }
|
||||
var pubMerchItems any
|
||||
if snap.MerchItemsJSON != "" { _ = json.Unmarshal([]byte(snap.MerchItemsJSON), &pubMerchItems) }
|
||||
resp := map[string]any{
|
||||
"club_id": snap.ClubID,
|
||||
"club_type": snap.ClubType,
|
||||
"club_name": snap.ClubName,
|
||||
"club_logo_url": snap.ClubLogoURL,
|
||||
"club_url": snap.ClubURL,
|
||||
"primary_color": snap.PrimaryColor,
|
||||
"secondary_color": snap.SecondaryColor,
|
||||
"accent_color": snap.AccentColor,
|
||||
"background_color": snap.BackgroundColor,
|
||||
"text_color": snap.TextColor,
|
||||
"font_heading": snap.FontHeading,
|
||||
"font_body": snap.FontBody,
|
||||
"sponsors_layout": snap.SponsorsLayout,
|
||||
"sponsors_theme": snap.SponsorsTheme,
|
||||
"facebook_url": snap.FacebookURL,
|
||||
"instagram_url": snap.InstagramURL,
|
||||
"youtube_url": snap.YoutubeURL,
|
||||
"gallery_url": snap.GalleryURL,
|
||||
"gallery_label": snap.GalleryLabel,
|
||||
"videos_module_enabled": snap.VideosModuleEnabled,
|
||||
"videos_style": snap.VideosStyle,
|
||||
"videos_source": snap.VideosSource,
|
||||
"videos_limit": snap.VideosLimit,
|
||||
"videos": pubVids,
|
||||
"videos_items": pubVidsItems,
|
||||
"merch_module_enabled": snap.MerchModuleEnabled,
|
||||
"merch_style": snap.MerchStyle,
|
||||
"merch_source": snap.MerchSource,
|
||||
"merch_limit": snap.MerchLimit,
|
||||
"merch_items": pubMerchItems,
|
||||
"about_html": snap.AboutHTML,
|
||||
"show_about_in_nav": snap.ShowAboutInNav,
|
||||
"custom_nav": snap.CustomNav,
|
||||
"contact_address": snap.ContactAddress,
|
||||
"contact_city": snap.ContactCity,
|
||||
"contact_zip": snap.ContactZip,
|
||||
"contact_country": snap.ContactCountry,
|
||||
"contact_phone": snap.ContactPhone,
|
||||
"contact_email": snap.ContactEmail,
|
||||
"location_latitude": snap.LocationLatitude,
|
||||
"location_longitude": snap.LocationLongitude,
|
||||
"map_zoom_level": snap.MapZoomLevel,
|
||||
"map_style": snap.MapStyle,
|
||||
"show_map_on_homepage": snap.ShowMapOnHomepage,
|
||||
}
|
||||
b, _ := json.MarshalIndent(resp, "", " ")
|
||||
outPath := filepath.Join("cache", "prefetch", "settings.json")
|
||||
_ = os.MkdirAll(filepath.Dir(outPath), 0o755)
|
||||
tmp := outPath + ".tmp"
|
||||
_ = os.WriteFile(tmp, b, 0o644)
|
||||
_ = os.Rename(tmp, outPath)
|
||||
}(s)
|
||||
go services.PrefetchOnce(baseURL)
|
||||
}
|
||||
go func(snap models.Settings) {
|
||||
defer func() { _ = recover() }()
|
||||
snap.LoadCustomNav()
|
||||
var pubVids []string
|
||||
if snap.VideosJSON != "" { _ = json.Unmarshal([]byte(snap.VideosJSON), &pubVids) }
|
||||
var pubVidsItems any
|
||||
if snap.VideosItemsJSON != "" { _ = json.Unmarshal([]byte(snap.VideosItemsJSON), &pubVidsItems) }
|
||||
var pubMerchItems any
|
||||
if snap.MerchItemsJSON != "" { _ = json.Unmarshal([]byte(snap.MerchItemsJSON), &pubMerchItems) }
|
||||
resp := map[string]any{
|
||||
"club_id": snap.ClubID,
|
||||
"club_type": snap.ClubType,
|
||||
"club_name": snap.ClubName,
|
||||
"club_logo_url": snap.ClubLogoURL,
|
||||
"club_url": snap.ClubURL,
|
||||
"primary_color": snap.PrimaryColor,
|
||||
"secondary_color": snap.SecondaryColor,
|
||||
"accent_color": snap.AccentColor,
|
||||
"background_color": snap.BackgroundColor,
|
||||
"text_color": snap.TextColor,
|
||||
"font_heading": snap.FontHeading,
|
||||
"font_body": snap.FontBody,
|
||||
"sponsors_layout": snap.SponsorsLayout,
|
||||
"sponsors_theme": snap.SponsorsTheme,
|
||||
"facebook_url": snap.FacebookURL,
|
||||
"instagram_url": snap.InstagramURL,
|
||||
"youtube_url": snap.YoutubeURL,
|
||||
"gallery_url": snap.GalleryURL,
|
||||
"gallery_label": snap.GalleryLabel,
|
||||
"videos_module_enabled": snap.VideosModuleEnabled,
|
||||
"videos_style": snap.VideosStyle,
|
||||
"videos_source": snap.VideosSource,
|
||||
"videos_limit": snap.VideosLimit,
|
||||
"videos": pubVids,
|
||||
"videos_items": pubVidsItems,
|
||||
"merch_module_enabled": snap.MerchModuleEnabled,
|
||||
"merch_style": snap.MerchStyle,
|
||||
"merch_source": snap.MerchSource,
|
||||
"merch_limit": snap.MerchLimit,
|
||||
"merch_items": pubMerchItems,
|
||||
"about_html": snap.AboutHTML,
|
||||
"show_about_in_nav": snap.ShowAboutInNav,
|
||||
"custom_nav": snap.CustomNav,
|
||||
"contact_address": snap.ContactAddress,
|
||||
"contact_city": snap.ContactCity,
|
||||
"contact_zip": snap.ContactZip,
|
||||
"contact_country": snap.ContactCountry,
|
||||
"contact_phone": snap.ContactPhone,
|
||||
"contact_email": snap.ContactEmail,
|
||||
"location_latitude": snap.LocationLatitude,
|
||||
"location_longitude": snap.LocationLongitude,
|
||||
"map_zoom_level": snap.MapZoomLevel,
|
||||
"map_style": snap.MapStyle,
|
||||
"show_map_on_homepage": snap.ShowMapOnHomepage,
|
||||
}
|
||||
b, _ := json.MarshalIndent(resp, "", " ")
|
||||
outPath := filepath.Join("cache", "prefetch", "settings.json")
|
||||
_ = os.MkdirAll(filepath.Dir(outPath), 0o755)
|
||||
tmp := outPath + ".tmp"
|
||||
_ = os.WriteFile(tmp, b, 0o644)
|
||||
_ = os.Rename(tmp, outPath)
|
||||
}(s)
|
||||
go services.PrefetchOnce(getPrefetchBaseURL())
|
||||
if strings.TrimSpace(s.YoutubeURL) != "" {
|
||||
go func(u string) { _ = services.RefreshYouTubeChannelNow(u) }(s.YoutubeURL)
|
||||
}
|
||||
@@ -2245,7 +2236,7 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
|
||||
logger.Info("Initial settings saved: club_id=%s club_name=%s gallery_url=%s gallery_label=%s", s.ClubID, s.ClubName, s.GalleryURL, s.GalleryLabel)
|
||||
|
||||
// Immediately write public settings cache from current Settings snapshot
|
||||
func() {
|
||||
go func() {
|
||||
defer func() { _ = recover() }()
|
||||
s.LoadCustomNav()
|
||||
var pubVids []string
|
||||
@@ -2313,28 +2304,20 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
|
||||
logger.Info("Default homepage page elements seeded")
|
||||
|
||||
// Run all setup operations asynchronously in background to provide immediate response
|
||||
scheme := "http"
|
||||
if c.Request.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
host := c.Request.Host
|
||||
|
||||
logger.Info("Starting initial data prefetch and setup operations in background...")
|
||||
|
||||
// Run all setup operations in a single background goroutine
|
||||
go func(settingsID uint, youtubeURL, galleryURL, adminEmail, baseHost string) {
|
||||
go func(settingsID uint, youtubeURL, galleryURL, adminEmail string) {
|
||||
defer func() { _ = recover() }()
|
||||
|
||||
// 1. Trigger prefetch (matches, standings, etc.)
|
||||
if baseHost != "" {
|
||||
baseURL := scheme + "://" + baseHost + "/api/v1"
|
||||
services.PrefetchOnce(baseURL)
|
||||
logger.Info("Background prefetch completed")
|
||||
baseURL := getPrefetchBaseURL()
|
||||
services.PrefetchOnce(baseURL)
|
||||
logger.Info("Background prefetch completed")
|
||||
|
||||
// Auto-populate competition aliases from FACR data
|
||||
bc.autoPopulateCompetitionAliases()
|
||||
logger.Info("Background competition aliases populated")
|
||||
}
|
||||
// Auto-populate competition aliases from FACR data
|
||||
bc.autoPopulateCompetitionAliases()
|
||||
logger.Info("Background competition aliases populated")
|
||||
|
||||
// 2. If YouTube channel is configured, refresh its cache
|
||||
if strings.TrimSpace(youtubeURL) != "" {
|
||||
@@ -2368,7 +2351,7 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
|
||||
}
|
||||
|
||||
logger.Info("All background setup operations completed")
|
||||
}(s.ID, s.YoutubeURL, s.GalleryURL, admin.Email, host)
|
||||
}(s.ID, s.YoutubeURL, s.GalleryURL, admin.Email)
|
||||
|
||||
logger.Info("SetupInitialize finished successfully - background operations running")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Setup completed successfully"})
|
||||
|
||||
Reference in New Issue
Block a user