mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
new mongo
This commit is contained in:
parent
a2bfc907bb
commit
05cec1b10c
@ -28,9 +28,8 @@ import (
|
|||||||
|
|
||||||
// FriendMgo implements FriendModelInterface using MongoDB as the storage backend.
|
// FriendMgo implements FriendModelInterface using MongoDB as the storage backend.
|
||||||
type FriendMgo struct {
|
type FriendMgo struct {
|
||||||
coll *mongo.Collection
|
coll *mongo.Collection
|
||||||
owner dataver.DataLog
|
owner dataver.DataLog
|
||||||
friend dataver.DataLog
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFriendMongo creates a new instance of FriendMgo with the provided MongoDB database.
|
// NewFriendMongo creates a new instance of FriendMgo with the provided MongoDB database.
|
||||||
@ -50,11 +49,7 @@ func NewFriendMongo(db *mongo.Database) (relation.FriendModelInterface, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
friend, err := dataver.NewDataLog(db.Collection("friend_log"))
|
return &FriendMgo{coll: coll, owner: owner}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &FriendMgo{coll: coll, owner: owner, friend: friend}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create inserts multiple friend records.
|
// Create inserts multiple friend records.
|
||||||
@ -72,17 +67,6 @@ func (f *FriendMgo) Create(ctx context.Context, friends []*relation.FriendModel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, func() error {
|
|
||||||
mp := make(map[string][]string)
|
|
||||||
for _, friend := range friends {
|
|
||||||
mp[friend.FriendUserID] = append(mp[friend.FriendUserID], friend.OwnerUserID)
|
|
||||||
}
|
|
||||||
for friendUserID, ownerUserIDs := range mp {
|
|
||||||
if err := f.friend.WriteLog(ctx, friendUserID, ownerUserIDs, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,13 +80,6 @@ func (f *FriendMgo) Delete(ctx context.Context, ownerUserID string, friendUserID
|
|||||||
return mongoutil.DeleteOne(ctx, f.coll, filter)
|
return mongoutil.DeleteOne(ctx, f.coll, filter)
|
||||||
}, func() error {
|
}, func() error {
|
||||||
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, true)
|
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, true)
|
||||||
}, func() error {
|
|
||||||
for _, userID := range friendUserIDs {
|
|
||||||
if err := f.friend.WriteLog(ctx, userID, []string{ownerUserID}, true); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +96,6 @@ func (f *FriendMgo) UpdateByMap(ctx context.Context, ownerUserID string, friendU
|
|||||||
return mongoutil.UpdateOne(ctx, f.coll, filter, bson.M{"$set": args}, true)
|
return mongoutil.UpdateOne(ctx, f.coll, filter, bson.M{"$set": args}, true)
|
||||||
}, func() error {
|
}, func() error {
|
||||||
return f.owner.WriteLog(ctx, ownerUserID, []string{friendUserID}, false)
|
return f.owner.WriteLog(ctx, ownerUserID, []string{friendUserID}, false)
|
||||||
}, func() error {
|
|
||||||
return f.friend.WriteLog(ctx, friendUserID, []string{ownerUserID}, false)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +179,6 @@ func (f *FriendMgo) UpdateFriends(ctx context.Context, ownerUserID string, frien
|
|||||||
return mongoutil.Ignore(mongoutil.UpdateMany(ctx, f.coll, filter, update))
|
return mongoutil.Ignore(mongoutil.UpdateMany(ctx, f.coll, filter, update))
|
||||||
}, func() error {
|
}, func() error {
|
||||||
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, false)
|
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, false)
|
||||||
}, func() error {
|
|
||||||
for _, userID := range friendUserIDs {
|
|
||||||
if err := f.friend.WriteLog(ctx, userID, []string{ownerUserID}, true); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user