mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 11:22:10 +08:00 
			
		
		
		
	refactor: change incremental to full
This commit is contained in:
		
							parent
							
								
									904842b15d
								
							
						
					
					
						commit
						c5fa596cdd
					
				@ -187,10 +187,10 @@ func (o *GroupApi) GetIncrementalGroupMemberBatch(c *gin.Context) {
 | 
			
		||||
	apiresp.GinSuccess(c, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (o *GroupApi) GetIncrementalGroupMemberUserIDs(c *gin.Context) {
 | 
			
		||||
	a2r.Call(group.GroupClient.GetIncrementalGroupMemberUserIDs, o.Client, c)
 | 
			
		||||
func (o *GroupApi) GetFullGroupMemberUserIDs(c *gin.Context) {
 | 
			
		||||
	a2r.Call(group.GroupClient.GetFullGroupMemberUserIDs, o.Client, c)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (o *GroupApi) GetIncrementalJoinGroupIDs(c *gin.Context) {
 | 
			
		||||
	a2r.Call(group.GroupClient.GetIncrementalJoinGroupIDs, o.Client, c)
 | 
			
		||||
func (o *GroupApi) GetFullJoinGroupIDs(c *gin.Context) {
 | 
			
		||||
	a2r.Call(group.GroupClient.GetFullJoinGroupIDs, o.Client, c)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -120,8 +120,8 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En
 | 
			
		||||
		groupRouterGroup.POST("/get_incremental_join_group", g.GetIncrementalJoinGroup)
 | 
			
		||||
		groupRouterGroup.POST("/get_incremental_group_member", g.GetIncrementalGroupMember)
 | 
			
		||||
		groupRouterGroup.POST("/get_incremental_group_member_batch", g.GetIncrementalGroupMemberBatch)
 | 
			
		||||
		groupRouterGroup.POST("/get_incremental_group_member_user_ids", g.GetIncrementalGroupMemberUserIDs)
 | 
			
		||||
		groupRouterGroup.POST("/get_incremental_join_group_ids", g.GetIncrementalJoinGroupIDs)
 | 
			
		||||
		groupRouterGroup.POST("/get_full_group_member_user_ids", g.GetFullGroupMemberUserIDs)
 | 
			
		||||
		groupRouterGroup.POST("/get_full_join_group_ids", g.GetFullJoinGroupIDs)
 | 
			
		||||
	}
 | 
			
		||||
	// certificate
 | 
			
		||||
	authRouterGroup := r.Group("/auth")
 | 
			
		||||
 | 
			
		||||
@ -2,26 +2,15 @@ package group
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"crypto/md5"
 | 
			
		||||
	"encoding/binary"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/openimsdk/open-im-server/v3/internal/rpc/incrversion"
 | 
			
		||||
	"github.com/openimsdk/open-im-server/v3/pkg/authverify"
 | 
			
		||||
	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
 | 
			
		||||
	"github.com/openimsdk/open-im-server/v3/pkg/util/hashutil"
 | 
			
		||||
	pbgroup "github.com/openimsdk/protocol/group"
 | 
			
		||||
	"github.com/openimsdk/protocol/sdkws"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (s *groupServer) idHash(ids []string) uint64 {
 | 
			
		||||
	if len(ids) == 0 {
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	data, _ := json.Marshal(ids)
 | 
			
		||||
	sum := md5.Sum(data)
 | 
			
		||||
	return binary.BigEndian.Uint64(sum[:])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *groupServer) GetIncrementalGroupMemberUserIDs(ctx context.Context, req *pbgroup.GetIncrementalGroupMemberUserIDsReq) (*pbgroup.GetIncrementalGroupMemberUserIDsResp, error) {
 | 
			
		||||
func (s *groupServer) GetFullGroupMemberUserIDs(ctx context.Context, req *pbgroup.GetFullGroupMemberUserIDsReq) (*pbgroup.GetFullGroupMemberUserIDsResp, error) {
 | 
			
		||||
	vl, err := s.db.FindMaxGroupMemberVersionCache(ctx, req.GroupID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@ -30,11 +19,11 @@ func (s *groupServer) GetIncrementalGroupMemberUserIDs(ctx context.Context, req
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	idHash := s.idHash(userIDs)
 | 
			
		||||
	idHash := hashutil.IdHash(userIDs)
 | 
			
		||||
	if req.IdHash == idHash {
 | 
			
		||||
		userIDs = nil
 | 
			
		||||
	}
 | 
			
		||||
	return &pbgroup.GetIncrementalGroupMemberUserIDsResp{
 | 
			
		||||
	return &pbgroup.GetFullGroupMemberUserIDsResp{
 | 
			
		||||
		Version:   idHash,
 | 
			
		||||
		VersionID: vl.ID.Hex(),
 | 
			
		||||
		Equal:     req.IdHash == idHash,
 | 
			
		||||
@ -42,7 +31,7 @@ func (s *groupServer) GetIncrementalGroupMemberUserIDs(ctx context.Context, req
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *groupServer) GetIncrementalJoinGroupIDs(ctx context.Context, req *pbgroup.GetIncrementalJoinGroupIDsReq) (*pbgroup.GetIncrementalJoinGroupIDsResp, error) {
 | 
			
		||||
func (s *groupServer) GetFullJoinGroupIDs(ctx context.Context, req *pbgroup.GetFullJoinGroupIDsReq) (*pbgroup.GetFullJoinGroupIDsResp, error) {
 | 
			
		||||
	vl, err := s.db.FindMaxJoinGroupVersionCache(ctx, req.UserID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@ -51,11 +40,11 @@ func (s *groupServer) GetIncrementalJoinGroupIDs(ctx context.Context, req *pbgro
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	idHash := s.idHash(groupIDs)
 | 
			
		||||
	idHash := hashutil.IdHash(groupIDs)
 | 
			
		||||
	if req.IdHash == idHash {
 | 
			
		||||
		groupIDs = nil
 | 
			
		||||
	}
 | 
			
		||||
	return &pbgroup.GetIncrementalJoinGroupIDsResp{
 | 
			
		||||
	return &pbgroup.GetFullJoinGroupIDsResp{
 | 
			
		||||
		Version:   idHash,
 | 
			
		||||
		VersionID: vl.ID.Hex(),
 | 
			
		||||
		Equal:     req.IdHash == idHash,
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								pkg/util/hashutil/id.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								pkg/util/hashutil/id.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
package hashutil
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/md5"
 | 
			
		||||
	"encoding/binary"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func IdHash(ids []string) uint64 {
 | 
			
		||||
	if len(ids) == 0 {
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	data, _ := json.Marshal(ids)
 | 
			
		||||
	sum := md5.Sum(data)
 | 
			
		||||
	return binary.BigEndian.Uint64(sum[:])
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user