This commit is contained in:
xing 2022-12-28 14:24:59 +08:00
parent 44ad7f2177
commit d720ba21ec
3 changed files with 9 additions and 4 deletions

View File

@ -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]

View File

@ -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
}

View File

@ -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 != "") {