From 366c05e4c33231283c1a0b28e9b1eca4aea02603 Mon Sep 17 00:00:00 2001 From: OpenIM-Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Thu, 17 Sep 2026 18:32:53 +0800 Subject: [PATCH] fix(msg): correct gap message document limit --- pkg/common/storage/model/msg.go | 2 +- pkg/common/storage/model/msg_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 pkg/common/storage/model/msg_test.go 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) + } + } +}