diff --git a/pkg/common/storage/model/msg.go b/pkg/common/storage/model/msg.go index 2bb4882f7..aeaf866ed 100644 --- a/pkg/common/storage/model/msg.go +++ b/pkg/common/storage/model/msg.go @@ -133,7 +133,7 @@ func (*MsgDocModel) GetMsgIndex(seq int64) int64 { } func (*MsgDocModel) GetLimitForSingleDoc(seq int64) int64 { - return seq % singleGocMsgNum + return (seq - 1) % singleGocMsgNum } func (*MsgDocModel) indexGen(conversationID string, seqSuffix int64) string { diff --git a/pkg/common/storage/model/msg_test.go b/pkg/common/storage/model/msg_test.go new file mode 100644 index 000000000..0a406a172 --- /dev/null +++ b/pkg/common/storage/model/msg_test.go @@ -0,0 +1,12 @@ +package model + +import "testing" + +func TestMsgDocModelGetLimitForSingleDoc(t *testing.T) { + model := new(MsgDocModel) + for _, test := range []struct{ seq, want int64 }{{1, 0}, {99, 98}, {100, 99}, {101, 0}} { + if got := model.GetLimitForSingleDoc(test.seq); got != test.want { + t.Errorf("GetLimitForSingleDoc(%d) = %d, want %d", test.seq, got, test.want) + } + } +}