diff --git a/actions/common/common.go b/actions/common/common.go index 6fb5ba7..4dc60e9 100644 --- a/actions/common/common.go +++ b/actions/common/common.go @@ -24,7 +24,7 @@ var monthPostsCache *cache.MapCache[string, []uint64] var postListIdsCache *cache.MapCache[string, PostIds] var searchPostIdsCache *cache.MapCache[string, PostIds] var maxPostIdCache *cache.SliceCache[uint64] -var TotalRaw int +var TotalRaw int64 var usersCache *cache.MapCache[uint64, wp.Users] var usersNameCache *cache.MapCache[string, wp.Users] var commentsCache *cache.MapCache[uint64, wp.Comments] diff --git a/actions/common/posts.go b/actions/common/posts.go index da54de1..ab2d95d 100644 --- a/actions/common/posts.go +++ b/actions/common/posts.go @@ -10,6 +10,7 @@ import ( "github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp" "strings" + "sync/atomic" "time" ) @@ -105,8 +106,10 @@ func searchPostIds(args ...any) (ids PostIds, err error) { ids.Ids = append(ids.Ids, posts.Id) } ids.Length = total - if total > TotalRaw { - TotalRaw = total + totalR := int(atomic.LoadInt64(&TotalRaw)) + if total > totalR { + tt := int64(total) + atomic.StoreInt64(&TotalRaw, tt) } return } diff --git a/actions/index.go b/actions/index.go index 19d8c97..a4f5a42 100644 --- a/actions/index.go +++ b/actions/index.go @@ -15,6 +15,7 @@ import ( "regexp" "strconv" "strings" + "sync/atomic" ) type indexHandle struct { @@ -159,7 +160,8 @@ func (h *indexHandle) parseParams() (err error) { h.page = pa } } - if common.TotalRaw > 0 && common.TotalRaw < (h.page-1)*h.pageSize { + total := int(atomic.LoadInt64(&common.TotalRaw)) + if total > 0 && total < (h.page-1)*h.pageSize { h.page = 1 } if h.page > 1 && (h.category != "" || h.search != "" || month != "") {