Skip to content

Commit

Permalink
deps: Merge #764 #765 #766 #767 PRs into pre-release-v3.8.2 (#768)
Browse files Browse the repository at this point in the history
* fix: fix temp file don't remove when upload file. (#764)

* build: improve cleanup after ms PR merged.

* fix: fix temp file don't remove when upload file.

* Fix local cache: user cache and group member cache (#765)

* fix: group member local cache

* fix: user local cache

* fix: Change check reinstall logic (#766)

* fix: check reinstall

* fix: check reinstall

* fix: GetGroupMembersInfoFunc (#767)

---------

Co-authored-by: Monet Lee <[email protected]>
Co-authored-by: icey-yu <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent 4d387f3 commit 174880b
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 33 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/cleanup-after-milestone-prs-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4.2.0

- name: Get the PR title and extract PR numbers
id: extract_pr_numbers
Expand All @@ -36,15 +36,6 @@ jobs:
echo "proceed=false" >> $GITHUB_OUTPUT
fi
- name: Delete branch after PR close
if: steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
echo "Branch to delete: $BRANCH_NAME"
git push origin --delete "$BRANCH_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Use extracted PR numbers and label PRs
if: (steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')) && github.event.pull_request.merged == true
run: |
Expand All @@ -63,3 +54,12 @@ jobs:
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete branch after PR close
if: steps.extract_pr_numbers.outputs.proceed == 'true' || contains(github.event.pull_request.labels.*.name, 'milestone-merge')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
echo "Branch to delete: $BRANCH_NAME"
git push origin --delete "$BRANCH_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ require (
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 10 additions & 5 deletions internal/conversation_msg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,16 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
break
}
name := s.FileElem.FileName

if name == "" {
name = s.FileElem.FilePath
}
if name == "" {
name = fmt.Sprintf("msg_file_%s.unknown", s.ClientMsgID)
}

delFile = append(delFile, s.FileElem.FilePath)

res, err := c.file.UploadFile(ctx, &file.UploadFileReq{
ContentType: content_type.GetType(s.FileElem.FileType, filepath.Ext(s.FileElem.FilePath), filepath.Ext(s.FileElem.FileName)),
Filepath: s.FileElem.FilePath,
Expand Down Expand Up @@ -657,7 +661,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
}

func (c *Conversation) sendMessageToServer(ctx context.Context, s *sdk_struct.MsgStruct, lc *model_struct.LocalConversation, callback open_im_sdk_callback.SendMsgCallBack,
delFile []string, offlinePushInfo *sdkws.OfflinePushInfo, options map[string]bool, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) {
delFiles []string, offlinePushInfo *sdkws.OfflinePushInfo, options map[string]bool, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) {
if isOnlineOnly {
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
Expand Down Expand Up @@ -709,13 +713,14 @@ func (c *Conversation) sendMessageToServer(ctx context.Context, s *sdk_struct.Ms
s.ServerMsgID = sendMsgResp.ServerMsgID
go func() {
//remove media cache file
for _, v := range delFile {
err := os.Remove(v)
for _, file := range delFiles {
err := os.Remove(file)
if err != nil {
// log.Error("", "remove failed,", err.Error(), v)
log.ZError(ctx, "delete temp File is failed", err, "filePath", file)
}
// log.Debug("", "remove file: ", v)
// log.ZDebug(ctx, "remove temp file:", "file", file)
}

c.updateMsgStatusAndTriggerConversation(ctx, sendMsgResp.ClientMsgID, sendMsgResp.ServerMsgID, sendMsgResp.SendTime, constant.MsgStatusSendSuccess, s, lc, isOnlineOnly)
}()
return s, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/conversation_msg/message_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func (c *Conversation) groupHandle(ctx context.Context, self, others []*model_st
}
for _, chatLog := range allMessage {
if g, ok := groupMap[chatLog.SendID]; ok { // If group member info is successfully retrieved
log.ZDebug(ctx, "find in GetGroupMemberNameAndFaceURL", "sendID", chatLog.SendID, "faceURL", g.FaceURL, "nickName", g.Nickname)
if g.FaceURL != "" && g.Nickname != "" {
chatLog.SenderFaceURL = g.FaceURL
chatLog.SenderNickname = g.Nickname
Expand All @@ -386,6 +387,7 @@ func (c *Conversation) groupHandle(ctx context.Context, self, others []*model_st
if err != nil {
log.ZWarn(ctx, "getUserNameAndFaceURL error", err, "senderID", chatLog.SendID)
} else if faceURL != "" && name != "" {
log.ZDebug(ctx, "find in getUserNameAndFaceURL", "sendID", chatLog.SendID, "faceURL", faceURL, "nickName", name)
chatLog.SenderFaceURL = faceURL
chatLog.SenderNickname = name
}
Expand Down
8 changes: 5 additions & 3 deletions internal/group/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package group
import (
"context"
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
"github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/utils/datautil"
)

Expand All @@ -20,21 +21,22 @@ func (g *Group) GetGroupMembersInfoFunc(ctx context.Context, groupID string, use

for _, userID := range userIDs {
key := g.buildGroupMemberKey(groupID, userID)
if member, ok := g.groupMemberCache.Load(groupID); ok {
res[key] = member
if member, ok := g.groupMemberCache.Load(key); ok {
res[userID] = member
} else {
missingKeys = append(missingKeys, userIDs...)
}
}

log.ZDebug(ctx, "GetGroupMembersInfoFunc fetch", "missingKeys", missingKeys)
fetchData, err := fetchFunc(ctx, missingKeys)
if err != nil {
return nil, err
}

for i, data := range fetchData {
key := g.buildGroupMemberKey(groupID, data.UserID)
res[key] = fetchData[i]
res[data.UserID] = fetchData[i]
g.groupMemberCache.Store(key, fetchData[i])
}

Expand Down
1 change: 1 addition & 0 deletions internal/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (g *Group) initSyncer() {
return g.db.DeleteGroupMember(ctx, value.GroupID, value.UserID)
}),
syncer.WithUpdate[*model_struct.LocalGroupMember, group.GetGroupMemberListResp, [2]string](func(ctx context.Context, server, local *model_struct.LocalGroupMember) error {
g.groupMemberCache.Delete(g.buildGroupMemberKey(server.GroupID, server.UserID))
return g.db.UpdateGroupMember(ctx, server)
}),
syncer.WithUUID[*model_struct.LocalGroupMember, group.GetGroupMemberListResp, [2]string](func(value *model_struct.LocalGroupMember) [2]string {
Expand Down
30 changes: 21 additions & 9 deletions internal/interaction/msg_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error {
log.ZError(ctx, "get conversation id list failed", err)
return err
}

if len(conversationIDList) == 0 {
m.reinstalled = true
version, err := m.db.GetAppSDKVersion(ctx)
if err != nil {
return err
}
if !version.Installed {
m.reinstalled = true
}
}

// TODO With a large number of sessions, this could potentially cause blocking and needs optimization.
Expand Down Expand Up @@ -248,6 +255,11 @@ func (m *MsgSyncer) compareSeqsAndBatchSync(ctx context.Context, maxSeqToSync ma
}
}
defer func() {
if err := m.db.SetAppSDKVersion(ctx, &model_struct.LocalAppSDKVersion{
Installed: true,
}); err != nil {
log.ZError(ctx, "SetAppSDKVersion err", err)
}
m.reinstalled = false
}()
_ = m.syncAndTriggerReinstallMsgs(m.ctx, needSyncSeqMap, pullNums)
Expand All @@ -269,24 +281,24 @@ func (m *MsgSyncer) compareSeqsAndBatchSync(ctx context.Context, maxSeqToSync ma

// startSync checks if the sync is already in progress.
// If syncing is in progress, it returns false. Otherwise, it starts syncing and returns true.
func (ms *MsgSyncer) startSync() bool {
ms.isSyncingLock.Lock()
defer ms.isSyncingLock.Unlock()
func (m *MsgSyncer) startSync() bool {
m.isSyncingLock.Lock()
defer m.isSyncingLock.Unlock()

if ms.isSyncing {
if m.isSyncing {
// If already syncing, return false
return false
}

// Set syncing to true and start the sync
ms.isSyncing = true
m.isSyncing = true

// Create a goroutine that waits for 5 seconds and then sets isSyncing to false
go func() {
time.Sleep(5 * time.Second)
ms.isSyncingLock.Lock()
ms.isSyncing = false
ms.isSyncingLock.Unlock()
m.isSyncingLock.Lock()
m.isSyncing = false
m.isSyncingLock.Unlock()
}()

return true
Expand Down
5 changes: 3 additions & 2 deletions internal/relation/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Relation struct {
db db_interface.DataBase
user *user.User
friendSyncer *syncer.Syncer[*model_struct.LocalFriend, relation.GetPaginationFriendsResp, [2]string]
blockSyncer *syncer.Syncer[*model_struct.LocalBlack, syncer.NoResp, [2]string]
blackSyncer *syncer.Syncer[*model_struct.LocalBlack, syncer.NoResp, [2]string]
requestRecvSyncer *syncer.Syncer[*model_struct.LocalFriendRequest, syncer.NoResp, [2]string]
requestSendSyncer *syncer.Syncer[*model_struct.LocalFriendRequest, syncer.NoResp, [2]string]
conversationCh chan common.Cmd2Value
Expand All @@ -53,6 +53,7 @@ func (r *Relation) initSyncer() {
return r.db.DeleteFriendDB(ctx, value.FriendUserID)
}),
syncer.WithUpdate[*model_struct.LocalFriend, relation.GetPaginationFriendsResp, [2]string](func(ctx context.Context, server, local *model_struct.LocalFriend) error {
r.user.UserCache.Delete(server.FriendUserID)
return r.db.UpdateFriend(ctx, server)
}),
syncer.WithUUID[*model_struct.LocalFriend, relation.GetPaginationFriendsResp, [2]string](func(value *model_struct.LocalFriend) [2]string {
Expand Down Expand Up @@ -132,7 +133,7 @@ func (r *Relation) initSyncer() {
syncer.WithFullSyncLimit[*model_struct.LocalFriend, relation.GetPaginationFriendsResp, [2]string](friendSyncLimit),
)

r.blockSyncer = syncer.New[*model_struct.LocalBlack, syncer.NoResp, [2]string](func(ctx context.Context, value *model_struct.LocalBlack) error {
r.blackSyncer = syncer.New[*model_struct.LocalBlack, syncer.NoResp, [2]string](func(ctx context.Context, value *model_struct.LocalBlack) error {
return r.db.InsertBlack(ctx, value)
}, func(ctx context.Context, value *model_struct.LocalBlack) error {
return r.db.DeleteBlack(ctx, value.BlockUserID)
Expand Down
4 changes: 2 additions & 2 deletions internal/relation/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *Relation) SyncAllBlackList(ctx context.Context) error {
return err
}
log.ZDebug(ctx, "black from local", "data", localData)
return r.blockSyncer.Sync(ctx, datautil.Batch(ServerBlackToLocalBlack, serverData), localData, nil)
return r.blackSyncer.Sync(ctx, datautil.Batch(ServerBlackToLocalBlack, serverData), localData, nil)
}

func (r *Relation) SyncAllBlackListWithoutNotice(ctx context.Context) error {
Expand All @@ -118,7 +118,7 @@ func (r *Relation) SyncAllBlackListWithoutNotice(ctx context.Context) error {
return err
}
log.ZDebug(ctx, "black from local", "data", localData)
return r.blockSyncer.Sync(ctx, datautil.Batch(ServerBlackToLocalBlack, serverData), localData, nil, false, true)
return r.blackSyncer.Sync(ctx, datautil.Batch(ServerBlackToLocalBlack, serverData), localData, nil, false, true)
}

func (r *Relation) GetDesignatedFriends(ctx context.Context, friendIDs []string) ([]*sdkws.FriendInfo, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (u *User) initSyncer() {
return fmt.Errorf("not support delete user %s", value.UserID)
},
func(ctx context.Context, serverUser, localUser *model_struct.LocalUser) error {
u.UserCache.Delete(localUser.UserID)
return u.DataBase.UpdateLoginUser(context.Background(), serverUser)
},
func(user *model_struct.LocalUser) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/group_member_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *DataBase) GetGroupSomeMemberInfo(ctx context.Context, groupID string, u
d.mRWMutex.RLock()
defer d.mRWMutex.RUnlock()
var groupMemberList []*model_struct.LocalGroupMember
err := d.conn.WithContext(ctx).Where("group_id = ? And user_id IN ? ", groupID, userIDList).Find(&groupMemberList).Error
err := d.conn.WithContext(ctx).Where("group_id = ? AND user_id IN ? ", groupID, userIDList).Find(&groupMemberList).Error
return groupMemberList, errs.WrapMsg(err, "GetGroupMemberListByGroupID failed ")
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/db/model_struct/data_model_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ func (LocalVersionSync) TableName() string {
}

type LocalAppSDKVersion struct {
Version string `gorm:"column:version;type:varchar(255);primary_key" json:"version"`
Version string `gorm:"column:version;type:varchar(255);primary_key" json:"version"`
Installed bool `gorm:"column:installed" json:"installed"` // Mark whether it has already been loaded
}

func (LocalAppSDKVersion) TableName() string {
Expand Down
20 changes: 20 additions & 0 deletions test/long_conn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package test

import (
"github.com/openimsdk/openim-sdk-core/v3/open_im_sdk"
"testing"
"time"
)

func Test_SubscribeUsersStatus(t *testing.T) {
time.Sleep(time.Second)
message, err := open_im_sdk.UserForSDK.LongConnMgr().SubscribeUsersStatus(ctx, []string{"5975996883"})
if err != nil {
t.Error(err)
}
t.Log(message)
ch := make(chan struct{})
select {
case <-ch:
}
}

0 comments on commit 174880b

Please sign in to comment.