Skip to content

Commit

Permalink
fix: replace version from etcd version to local version. (#568)
Browse files Browse the repository at this point in the history
* fix: token cb update.

Signed-off-by: Gordon <[email protected]>

* fix: get correct member list by filter.

Signed-off-by: Gordon <[email protected]>

* fix: update sdk version to 3.8.0.

Signed-off-by: Gordon <[email protected]>

* fix: replace version from etcd version to local version.

Signed-off-by: Gordon <[email protected]>

---------

Signed-off-by: Gordon <[email protected]>
  • Loading branch information
FGadvancer authored Jul 4, 2024
1 parent d34871c commit 38e2d36
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 39 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ require (
github.com/openimsdk/protocol v0.0.69-alpha.16
github.com/openimsdk/tools v0.0.49-alpha.40
github.com/patrickmn/go-cache v2.1.0+incompatible
go.etcd.io/etcd/api/v3 v3.5.13
golang.org/x/image v0.15.0
gorm.io/gorm v1.25.10
)

require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
Expand All @@ -39,5 +37,3 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.62.1 // indirect
)

//replace github.com/openimsdk/protocol => /Users/chao/Desktop/project/protocol
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -41,8 +39,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.etcd.io/etcd/api/v3 v3.5.13 h1:8WXU2/NBge6AUF1K1gOexB6e07NgsN1hXK0rSTtgSp4=
go.etcd.io/etcd/api/v3 v3.5.13/go.mod h1:gBqlqkcMMZMVTMm4NDZloEVJzxQOQIls8splbqBDa0c=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
Expand All @@ -65,8 +61,6 @@ google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E=
Expand Down
15 changes: 9 additions & 6 deletions internal/friend/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func (f *Friend) GetSpecifiedFriendsInfo(ctx context.Context, friendUserIDList [
func(ctx context.Context, values []*model_struct.LocalFriend) error {
return f.db.BatchInsertFriend(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
return f.db.GetFriendInfoList(ctx, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) {
localFriends, err := f.db.GetFriendInfoList(ctx, userIDs)
return localFriends, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
serverFriend, err := f.GetDesignatedFriends(ctx, userIDs)
Expand Down Expand Up @@ -201,8 +202,9 @@ func (f *Friend) GetFriendListPage(ctx context.Context, offset, count int32) ([]
func(ctx context.Context, values []*model_struct.LocalFriend) error {
return f.db.BatchInsertFriend(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
return f.db.GetFriendInfoList(ctx, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) {
localFriendList, err := f.db.GetFriendInfoList(ctx, userIDs)
return localFriendList, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
serverFriend, err := f.GetDesignatedFriends(ctx, userIDs)
Expand Down Expand Up @@ -249,8 +251,9 @@ func (f *Friend) GetFriendListPageV2(ctx context.Context, offset, count int32) (
func(ctx context.Context, values []*model_struct.LocalFriend) error {
return f.db.BatchInsertFriend(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
return f.db.GetFriendInfoList(ctx, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) {
localFriendList, err := f.db.GetFriendInfoList(ctx, userIDs)
return localFriendList, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) {
serverFriend, err := f.GetDesignatedFriends(ctx, userIDs)
Expand Down
69 changes: 53 additions & 16 deletions internal/group/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ func (g *Group) GetJoinedGroupListPage(ctx context.Context, offset, count int32)
func(ctx context.Context, values []*model_struct.LocalGroup) error {
return g.db.BatchInsertGroup(ctx, values)
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
return g.db.GetGroups(ctx, groupIDs)
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) {
localGroups, err := g.db.GetGroups(ctx, groupIDs)
return localGroups, true, err
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs)
Expand All @@ -198,8 +199,9 @@ func (g *Group) GetSpecifiedGroupsInfo(ctx context.Context, groupIDs []string) (
func(ctx context.Context, values []*model_struct.LocalGroup) error {
return g.db.BatchInsertGroup(ctx, values)
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
return g.db.GetGroups(ctx, groupIDs)
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) {
localGroups, err := g.db.GetGroups(ctx, groupIDs)
return localGroups, true, err
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs)
Expand All @@ -223,8 +225,9 @@ func (g *Group) GetJoinedGroupListPageV2(ctx context.Context, offset, count int3
func(ctx context.Context, values []*model_struct.LocalGroup) error {
return g.db.BatchInsertGroup(ctx, values)
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
return g.db.GetGroups(ctx, groupIDs)
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) {
localGroups, err := g.db.GetGroups(ctx, groupIDs)
return localGroups, true, err
},
func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) {
serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs)
Expand Down Expand Up @@ -289,8 +292,9 @@ func (g *Group) GetGroupMemberListByJoinTimeFilter(ctx context.Context, groupID
func(ctx context.Context, values []*model_struct.LocalGroupMember) error {
return g.db.BatchInsertGroupMember(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
return g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) {
localGroupMembers, err := g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs)
return localGroupMembers, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs)
Expand Down Expand Up @@ -319,8 +323,9 @@ func (g *Group) GetGroupMemberListByJoinTimeFilterV2(ctx context.Context, groupI
func(ctx context.Context, values []*model_struct.LocalGroupMember) error {
return g.db.BatchInsertGroupMember(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
return g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) {
localGroupMembers, err := g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs)
return localGroupMembers, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs)
Expand Down Expand Up @@ -372,8 +377,9 @@ func (g *Group) GetSpecifiedGroupMembersInfo(ctx context.Context, groupID string
func(ctx context.Context, values []*model_struct.LocalGroupMember) error {
return g.db.BatchInsertGroupMember(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
return g.db.GetGroupSomeMemberInfo(ctx, groupID, userIDList)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) {
localGroupMembers, err := g.db.GetGroupSomeMemberInfo(ctx, groupID, userIDList)
return localGroupMembers, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs)
Expand Down Expand Up @@ -420,8 +426,24 @@ func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter,
func(ctx context.Context, values []*model_struct.LocalGroupMember) error {
return g.db.BatchInsertGroupMember(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
return g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) {
localGroupMembers, err := g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs)
if err != nil {
return nil, false, err
}
switch filter {
case constant.GroupFilterOwner:
fallthrough
case constant.GroupFilterAdmin:
fallthrough
case constant.GroupFilterOwnerAndAdmin:
return localGroupMembers, false, nil
case constant.GroupFilterAll:
case constant.GroupFilterOrdinaryUsers:
case constant.GroupFilterAdminAndOrdinaryUsers:
return localGroupMembers, true, nil
}
return nil, false, sdkerrs.ErrArgs
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs)
Expand All @@ -431,6 +453,20 @@ func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter,
return datautil.Batch(ServerGroupMemberToLocalGroupMember, serverGroupMember), nil
},
)
switch filter {
case constant.GroupFilterOrdinaryUsers:
groupOwnerAndGroupMember, err := g.db.GetGroupMemberListSplit(ctx, groupID, constant.GroupFilterOwnerAndAdmin, 0, 100)
if err != nil {
return nil, err
}
offset = offset + int32(len(groupOwnerAndGroupMember))
case constant.GroupFilterAdminAndOrdinaryUsers:
groupOwnerAndGroupMember, err := g.db.GetGroupMemberListSplit(ctx, groupID, constant.GroupFilterOwner, 0, 100)
if err != nil {
return nil, err
}
offset = offset + int32(len(groupOwnerAndGroupMember))
}
return dataFetcher.FetchWithPagination(ctx, int(offset), int(count))
}

Expand All @@ -445,8 +481,9 @@ func (g *Group) GetGroupMemberListV2(ctx context.Context, groupID string, filter
func(ctx context.Context, values []*model_struct.LocalGroupMember) error {
return g.db.BatchInsertGroupMember(ctx, values)
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
return g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs)
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) {
localGroupMembers, err := g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs)
return localGroupMembers, true, err
},
func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) {
serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs)
Expand Down
2 changes: 1 addition & 1 deletion msgtest/sdk_user_simulator/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
"github.com/openimsdk/openim-sdk-core/v3/version"
"github.com/openimsdk/tools/log"
"go.etcd.io/etcd/api/v3/version"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion open_im_sdk/init_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/openimsdk/openim-sdk-core/v3/pkg/ccontext"
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
"go.etcd.io/etcd/api/v3/version"
"github.com/openimsdk/openim-sdk-core/v3/version"
"strings"

"github.com/openimsdk/tools/log"
Expand Down
15 changes: 11 additions & 4 deletions pkg/datafetcher/datafetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DataFetcher[T any] struct {
}

// FetchDataFunc is a function type for fetching data
type FetchDataFunc[T any] func(ctx context.Context, uids []string) ([]T, error)
type FetchDataFunc[T any] func(ctx context.Context, uids []string) ([]T, bool, error)

// FetchFromServerFunc is a function type for fetching data from server
type FetchFromServerFunc[T any] func(ctx context.Context, uids []string) ([]T, error)
Expand Down Expand Up @@ -67,10 +67,13 @@ func (ds *DataFetcher[T]) FetchWithPagination(ctx context.Context, offset, limit

// FetchMissingAndFillLocal fetches missing data from server and fills local database
func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []string) ([]T, error) {
localData, err := ds.FetchFromLocal(ctx, uids)
localData, needServer, err := ds.FetchFromLocal(ctx, uids)
if err != nil {
return nil, err
}
if !needServer {
return localData, nil
}

localUIDSet := datautil.SliceSetAny(localData, ds.Key)

Expand Down Expand Up @@ -101,11 +104,15 @@ func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []s

// FetchMissingAndCombineLocal fetches missing data from the server and combines it with local data without inserting it into the local database
func (ds *DataFetcher[T]) FetchMissingAndCombineLocal(ctx context.Context, uids []string) ([]T, error) {
localData, err := ds.FetchFromLocal(ctx, uids)
localData, needServer, err := ds.FetchFromLocal(ctx, uids)
if err != nil {
return nil, err
}

if !needServer {
return localData, nil
}

localUIDSet := datautil.SliceSetAny(localData, ds.Key)

var missingUIDs []string
Expand Down Expand Up @@ -154,7 +161,7 @@ func (ds *DataFetcher[T]) FetchWithPaginationV2(ctx context.Context, offset, lim
}

func (ds *DataFetcher[T]) FetchMissingAndFillLocalV2(ctx context.Context, uids []string, isEnd bool) ([]T, bool, error) {
localData, err := ds.FetchFromLocal(ctx, uids)
localData, _, err := ds.FetchFromLocal(ctx, uids)
if err != nil {
return nil, false, err
}
Expand Down
2 changes: 1 addition & 1 deletion version/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.0
3.8.0

0 comments on commit 38e2d36

Please sign in to comment.