feat: implement true batchGetIncrGroupMember RPC method and dependency methods. (#2417)

* update wip contents.

* update protocol pkg.

* feat: add BatchOption struct and method.

* fix: remove unnecessary field.

* feat: implement true BatchGetIncrGroupMember RPC method and corresponding dependency methods.

* fix: update mongo version collection have unique index.

* optimize method structures.

* update resp in add sortVersion field.

* fix uncorrect condition.

* add errs pkg.
This commit is contained in:
Monet Lee
2024-07-19 17:20:11 +08:00
committed by GitHub
parent 6c8ac45137
commit d0d33b6b78
13 changed files with 454 additions and 61 deletions
+4 -7
View File
@@ -3,6 +3,7 @@ package incrversion
import (
"context"
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/tools/errs"
"go.mongodb.org/mongo-driver/bson/primitive"
@@ -20,7 +21,7 @@ const syncLimit = 200
const (
tagQuery = iota + 1
tagFull
tageEqual
tagEqual
)
type Option[A, B any] struct {
@@ -33,7 +34,6 @@ type Option[A, B any] struct {
Version func(ctx context.Context, dId string, version uint, limit int) (*model.VersionLog, error)
//SortID func(ctx context.Context, dId string) ([]string, error)
Find func(ctx context.Context, ids []string) ([]A, error)
ID func(elem A) string
Resp func(version *model.VersionLog, deleteIds []string, insertList, updateList []A, full bool) *B
}
@@ -60,9 +60,6 @@ func (o *Option[A, B]) check() error {
if o.Find == nil {
return o.newError("func find is nil")
}
if o.ID == nil {
return o.newError("func id is nil")
}
if o.Resp == nil {
return o.newError("func resp is nil")
}
@@ -100,7 +97,7 @@ func (o *Option[A, B]) getVersion(tag *int) (*model.VersionLog, error) {
return cache, nil
}
if o.VersionNumber == uint64(cache.Version) {
*tag = tageEqual
*tag = tagEqual
return cache, nil
}
*tag = tagQuery
@@ -123,7 +120,7 @@ func (o *Option[A, B]) Build() (*B, error) {
full = version.ID.Hex() != o.VersionID || uint64(version.Version) < o.VersionNumber || len(version.Logs) != version.LogLen
case tagFull:
full = true
case tageEqual:
case tagEqual:
full = false
default:
panic(fmt.Errorf("undefined tag %d", tag))