diff --git a/app/pkg/dao/comments.go b/app/pkg/dao/comments.go index 0cad097..ec71918 100644 --- a/app/pkg/dao/comments.go +++ b/app/pkg/dao/comments.go @@ -52,20 +52,33 @@ func PostComments(ctx context.Context, postId uint64, _ ...any) ([]uint64, error } func GetCommentByIds(ctx context.Context, ids []uint64, _ ...any) (map[uint64]models.Comments, error) { - m := make(map[uint64]models.Comments) - r, err := model.ChunkFind[models.Comments](ctx, 500, model.Conditions( - model.Where(model.SqlBuilder{ - {"comment_ID", "in", ""}, {"comment_approved", "1"}, - }), - model.Fields("*"), - model.In(slice.ToAnySlice(ids)), - )) - if err != nil { - return m, err + if len(ids) < 1 { + return nil, nil } - return slice.SimpleToMap(r, func(t models.Comments) uint64 { - return t.CommentId - }), err + m := make(map[uint64]models.Comments) + off := 0 + for { + id := slice.Slice(ids, off, 500) + if len(id) < 1 { + break + } + r, err := model.Finds[models.Comments](ctx, model.Conditions( + model.Where(model.SqlBuilder{ + {"comment_ID", "in", ""}, {"comment_approved", "1"}, + }), + model.Fields("*"), + model.In(slice.ToAnySlice(id)), + )) + if err != nil { + return m, err + } + for _, comments := range r { + m[comments.CommentId] = comments + } + off += 500 + } + + return m, nil } func GetIncreaseComment(ctx context.Context, currentData []uint64, k uint64, t time.Time, _ ...any) (data []uint64, save bool, refresh bool, err error) { diff --git a/cache/map.go b/cache/map.go index 6078ef3..cbb83e4 100644 --- a/cache/map.go +++ b/cache/map.go @@ -229,7 +229,7 @@ func (m *MapCache[K, V]) getBatchToMap(e Expend[K, V]) func(c context.Context, k r, er := m.batchCacheFn(ctx, maps.FilterToSlice(needIndex, func(k K, v int) (K, bool) { return k, true }), params...) - if err != nil { + if er != nil { err = er return } @@ -296,7 +296,7 @@ func (m *MapCache[K, V]) getBatchToMapes(c context.Context, key []K, timeout tim } rr, er := m.batchCacheFn(c, needFlushs, params...) - if err != nil { + if er != nil { err = er return } @@ -361,7 +361,7 @@ func (m *MapCache[K, V]) getCacheBatchs(c context.Context, key []K, timeout time } r, er := m.batchCacheFn(c, needFlushs, params...) - if err != nil { + if er != nil { err = er return } @@ -441,7 +441,7 @@ func (m *MapCache[K, V]) getBatches(e Expend[K, V]) func(ctx context.Context, ke r, er := m.batchCacheFn(ctx, maps.FilterToSlice(needIndex, func(k K, v int) (K, bool) { return k, true }), params...) - if err != nil { + if er != nil { err = er return } diff --git a/helper/slice/slice.go b/helper/slice/slice.go index 46488fc..afa88ff 100644 --- a/helper/slice/slice.go +++ b/helper/slice/slice.go @@ -152,13 +152,11 @@ func Slice[T any](arr []T, offset, length int) (r []T) { length = l - offset } if l > offset && l >= offset+length { - r = append(make([]T, 0, length), arr[offset:offset+length]...) - arr = append(arr[:offset], arr[offset+length:]...) + r = arr[offset : offset+length] } else if l <= offset { return } else if l > offset && l < offset+length { - r = append(make([]T, 0, length), arr[offset:]...) - arr = arr[:offset] + r = arr[offset:] } return } diff --git a/helper/slice/slices.go b/helper/slice/slices.go index b86e502..e6a39d2 100644 --- a/helper/slice/slices.go +++ b/helper/slice/slices.go @@ -8,6 +8,10 @@ func Splice[T any](a *[]T, offset, length int, replacement []T) []T { } if offset >= 0 { if offset+length > l { + if offset == 0 { + *a = []T{} + return arr[:l] + } return nil } else if l > offset && l < offset+length { v := arr[offset:l]