From d720ba21ec8c6b97839a486df8356b4f27c9b7e9 Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 28 Dec 2022 14:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/common/common.go | 2 +- actions/common/posts.go | 7 +++++-- actions/index.go | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) 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 != "") {