diff --git a/helper/html/html.go b/helper/html/html.go
index e26318e..32ace0c 100644
--- a/helper/html/html.go
+++ b/helper/html/html.go
@@ -32,6 +32,9 @@ const (
)
func SpecialChars(text string, flag ...int) string {
+ if len(text) < 1 {
+ return ""
+ }
flags := EntQuotes
if len(flag) > 0 {
flags = flag[0]
diff --git a/internal/pkg/cache/cache.go b/internal/pkg/cache/cache.go
index 445446d..1ef3a92 100644
--- a/internal/pkg/cache/cache.go
+++ b/internal/pkg/cache/cache.go
@@ -10,12 +10,10 @@ import (
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/safety"
- "sync"
"time"
)
var postContextCache *cache.MapCache[uint64, dao.PostContext]
-var archivesCaches *Arch
var categoryAndTagsCaches *cache.MapCache[int, []models.TermsMy]
var recentPostsCaches *cache.VarCache[[]models.Posts]
var recentCommentsCaches *cache.VarCache[[]models.Comments]
@@ -45,11 +43,6 @@ var allUsernameCache *cache.VarCache[map[string]struct{}]
func InitActionsCommonCache() {
c := config.GetConfig()
- archivesCaches = &Arch{
- mutex: &sync.Mutex{},
- fn: dao.Archives,
- data: *safety.NewVar([]models.PostArchive{}),
- }
searchPostIdsCache = cachemanager.MapCacheBy[string](dao.SearchPostIds, c.CacheTime.SearchPostCacheTime)
@@ -92,19 +85,19 @@ func InitActionsCommonCache() {
InitFeed()
}
-func Archives(ctx context.Context) (r []models.PostArchive) {
- return archivesCaches.getArchiveCache(ctx)
-}
-
type Arch struct {
- data safety.Var[[]models.PostArchive]
- mutex *sync.Mutex
+ data []models.PostArchive
fn func(context.Context) ([]models.PostArchive, error)
month time.Month
}
-func (a *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
- data := a.data.Load()
+var arch = safety.NewVar(Arch{
+ fn: dao.Archives,
+})
+
+func Archives(ctx context.Context) []models.PostArchive {
+ a := arch.Load()
+ data := a.data
l := len(data)
m := time.Now().Month()
if l > 0 && a.month != m || l < 1 {
@@ -113,10 +106,9 @@ func (a *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
logs.ErrPrintln(err, "set cache err[%s]")
return nil
}
- a.mutex.Lock()
- defer a.mutex.Unlock()
a.month = m
- a.data.Store(r)
+ a.data = r
+ arch.Store(a)
data = r
}
return data
diff --git a/internal/theme/wp/components/widget/search.go b/internal/theme/wp/components/widget/search.go
index 91ca6c8..5f8aa2f 100644
--- a/internal/theme/wp/components/widget/search.go
+++ b/internal/theme/wp/components/widget/search.go
@@ -72,9 +72,10 @@ func Search(h *wp.Handle, id string) string {
})
args = maps.Copy(args)
s := strings.ReplaceAll(searchTemplate, "{$form}", form)
- args["{$value}"] = ""
+ val := ""
if h.Scene() == constraints.Search {
- args["{$value}"] = html.SpecialChars(h.Index.Param.Search)
+ val = html.SpecialChars(h.Index.Param.Search)
}
+ s = strings.ReplaceAll(s, "{$value}", val)
return h.ComponentFilterFnHook(widgets.Search, str.Replace(s, args))
}
diff --git a/internal/theme/wp/customlogo.go b/internal/theme/wp/customlogo.go
index 1708910..573bcd9 100644
--- a/internal/theme/wp/customlogo.go
+++ b/internal/theme/wp/customlogo.go
@@ -6,8 +6,11 @@ import (
str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/pkg/cache"
"github.com/fthvgb1/wp-go/internal/wpconfig"
+ "sync"
)
+var logoLock = sync.Mutex{}
+
func CalCustomLogo(h *Handle) (r string) {
id := uint64(h.themeMods.CustomLogo)
if id < 1 {
@@ -30,7 +33,9 @@ func CalCustomLogo(h *Handle) (r string) {
"decoding": "async",
//"loading":"lazy",
}
+ logoLock.Lock()
img := wpconfig.Thumbnail(logo.AttachmentMetadata, siz, "", "")
+ logoLock.Unlock()
imgx["srcset"] = img.Srcset
imgx["sizes"] = img.Sizes
imgx["src"] = img.Path