From 4a79a57e408893f938b54bc97606886c09700edb Mon Sep 17 00:00:00 2001 From: hanzhixiao <709674996@qq.com> Date: Mon, 14 Aug 2023 11:43:21 +0800 Subject: [PATCH] fix:searchmsg Signed-off-by: hanzhixiao <709674996@qq.com> --- pkg/common/db/unrelation/msg.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index ce51ca49c..3db91bc50 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -1166,9 +1166,6 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa if err != nil { return 0, nil, err } - if len(msgsDocs) == 0 { - return 0, nil, errs.Wrap(mongo.ErrNoDocuments) - } msgs := make([]*table.MsgInfoModel, 0) for index := range msgsDocs { msgInfo := msgsDocs[index].Msg @@ -1207,7 +1204,9 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber n := int32(len(msgs)) - if start+req.Pagination.ShowNumber < n { + if start >= n { + return n, []*table.MsgInfoModel{}, nil + } else if start+req.Pagination.ShowNumber < n { msgs = msgs[start : start+req.Pagination.ShowNumber] } else { msgs = msgs[start:]