From 7bbc961f72becb9bd3a4036986be34910984487d Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 16 Nov 2023 22:52:14 +0800 Subject: [PATCH] optimize --- app/pkg/dao/comments.go | 5 +++-- model/querycondition.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/pkg/dao/comments.go b/app/pkg/dao/comments.go index f72435f..a061a1a 100644 --- a/app/pkg/dao/comments.go +++ b/app/pkg/dao/comments.go @@ -3,6 +3,7 @@ package dao import ( "context" "github.com/fthvgb1/wp-go/app/pkg/models" + "github.com/fthvgb1/wp-go/helper" "github.com/fthvgb1/wp-go/helper/number" "github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/model" @@ -11,7 +12,7 @@ import ( // RecentComments // param context.Context func RecentComments(ctx context.Context, a ...any) (r []models.Comments, err error) { - n := a[1].(int) + n := helper.ParseArgs(10, a...) return model.Finds[models.Comments](ctx, model.Conditions( model.Where(model.SqlBuilder{ {"comment_approved", "1"}, @@ -28,7 +29,7 @@ func RecentComments(ctx context.Context, a ...any) (r []models.Comments, err err // param1 context.Context // param2 postId func PostComments(ctx context.Context, postId uint64, _ ...any) ([]uint64, error) { - r, err := model.Finds[models.Comments](ctx, model.Conditions( + r, err := model.ChunkFind[models.Comments](ctx, 300, model.Conditions( model.Where(model.SqlBuilder{ {"comment_approved", "1"}, {"comment_post_ID", "=", number.IntToString(postId), "int"}, diff --git a/model/querycondition.go b/model/querycondition.go index d7daae8..b4485db 100644 --- a/model/querycondition.go +++ b/model/querycondition.go @@ -54,7 +54,7 @@ func chunkFind[T Model](db dbQuery, ctx context.Context, perLimit int, q *QueryC rr, err = finds[T](db, ctx, q) } offset += perLimit - if (err != nil && err != sql.ErrNoRows) || len(rr) < 1 { + if (err != nil && !errors.Is(err, sql.ErrNoRows)) || len(rr) < 1 { return } r = append(r, rr...)