优化
This commit is contained in:
parent
a24352d043
commit
52d3b89d27
|
@ -27,18 +27,28 @@ func recentComments(...any) (r []models.WpComments, err error) {
|
|||
}
|
||||
|
||||
func PostComments(ctx context.Context, Id uint64) ([]models.WpComments, error) {
|
||||
return postCommentCaches.GetCache(ctx, Id, time.Second, Id)
|
||||
ids, err := postCommentCaches.GetCache(ctx, Id, time.Second, Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetCommentByIds(ctx, ids)
|
||||
}
|
||||
|
||||
func postComments(args ...any) ([]models.WpComments, error) {
|
||||
func postComments(args ...any) ([]uint64, error) {
|
||||
postId := args[0].(uint64)
|
||||
return models.Find[models.WpComments](models.SqlBuilder{
|
||||
r, err := models.Find[models.WpComments](models.SqlBuilder{
|
||||
{"comment_approved", "1"},
|
||||
{"comment_post_ID", "=", strconv.FormatUint(postId, 10), "int"},
|
||||
}, "*", "", models.SqlBuilder{
|
||||
}, "comment_ID", "", models.SqlBuilder{
|
||||
{"comment_date_gmt", "asc"},
|
||||
{"comment_ID", "asc"},
|
||||
}, nil, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return helper.SliceMap(r, func(t models.WpComments) uint64 {
|
||||
return t.CommentId
|
||||
}), err
|
||||
}
|
||||
|
||||
func GetCommentById(ctx context.Context, id uint64) (models.WpComments, error) {
|
||||
|
|
|
@ -16,7 +16,7 @@ var archivesCaches *Arch
|
|||
var categoryCaches *cache.SliceCache[models.WpTermsMy]
|
||||
var recentPostsCaches *cache.SliceCache[models.WpPosts]
|
||||
var recentCommentsCaches *cache.SliceCache[models.WpComments]
|
||||
var postCommentCaches *cache.MapCache[uint64, []models.WpComments]
|
||||
var postCommentCaches *cache.MapCache[uint64, []uint64]
|
||||
var postsCache *cache.MapCache[uint64, models.WpPosts]
|
||||
var monthPostsCache *cache.MapCache[string, []uint64]
|
||||
var postListIdsCache *cache.MapCache[string, PostIds]
|
||||
|
@ -48,7 +48,7 @@ func InitActionsCommonCache() {
|
|||
|
||||
recentCommentsCaches = cache.NewSliceCache[models.WpComments](recentComments, vars.Conf.RecentCommentsCacheTime)
|
||||
|
||||
postCommentCaches = cache.NewMapCacheByFn[uint64, []models.WpComments](postComments, vars.Conf.PostCommentsCacheTime)
|
||||
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, vars.Conf.PostCommentsCacheTime)
|
||||
|
||||
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, vars.Conf.MaxPostIdCacheTime)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user