From 8d3197ee9801c62e33b6a9ef65749ecb225c57b7 Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 5 Jan 2024 00:01:57 +0800 Subject: [PATCH] optimize --- app/theme/wp/comments.go | 12 +----------- helper/slice/slices.go | 4 +--- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/app/theme/wp/comments.go b/app/theme/wp/comments.go index 44441f4..5a07ea0 100644 --- a/app/theme/wp/comments.go +++ b/app/theme/wp/comments.go @@ -45,7 +45,7 @@ func (c CommentHandle) findComments(ctx context.Context, timeout time.Duration, parentIds := slice.Map(comments, func(t models.Comments) uint64 { return t.CommentId }) - children, err := c.childrenComment(ctx, parentIds, timeout) + children, err := c.children.GetCacheBatch(ctx, parentIds, timeout) rr := slice.FilterAndMap(children, func(t []uint64) ([]uint64, bool) { return t, len(t) > 0 }) @@ -68,22 +68,12 @@ func (c CommentHandle) findComments(ctx context.Context, timeout time.Duration, return comments, nil } -func (c CommentHandle) childrenComment(ctx context.Context, ids []uint64, timeout time.Duration) ([][]uint64, error) { - v, err := c.children.GetCacheBatch(ctx, ids, timeout) - if err != nil { - return nil, err - } - - return slice.Copy(v), nil -} - func (c CommentHandle) formatComments(ctx context.Context, ids []uint64, timeout time.Duration) (html string, err error) { comments, err := c.ca.GetCacheBatch(ctx, ids, timeout) if err != nil { return "", err } if c.depth > 1 && c.depth < c.maxDepth { - comments = slice.Copy(comments) slice.Sort(comments, func(i, j models.Comments) bool { return c.html.FloorOrder(c.order, i, j) }) diff --git a/helper/slice/slices.go b/helper/slice/slices.go index 8acd482..f4cb2ab 100644 --- a/helper/slice/slices.go +++ b/helper/slice/slices.go @@ -87,9 +87,7 @@ func Push[T any](a *[]T, e ...T) { func Decompress[T any](a [][]T) (r []T) { for _, ts := range a { - for _, t := range ts { - r = append(r, t) - } + r = append(r, ts...) } return }