This commit is contained in:
aozhiwei 2024-03-24 10:11:45 +08:00
parent ed4769cfd6
commit 3e90315b75
2 changed files with 23 additions and 7 deletions

View File

@ -41,7 +41,9 @@ CREATE TABLE `t_friend_relationship` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id1` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号1', `account_id1` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号1',
`account_id2` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号2', `account_id2` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号2',
`add_time` int(11) NOT NULL DEFAULT '0' COMMENT '成为好友时间',
`deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除', `deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除',
`del_time` int(11) NOT NULL DEFAULT '0' COMMENT '删除时间',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`), PRIMARY KEY (`idx`),

View File

@ -8,15 +8,15 @@ import (
) )
type friendMgr struct { type friendMgr struct {
friendHash map[string]*map[string]int32 friendHash map[string]map[string]int32
blackHash map[string]*map[string]int32 blackHash map[string]map[string]int32
byBlackHash map[string]*map[string]int32 byBlackHash map[string]map[string]int32
} }
func (this *friendMgr) Init() { func (this *friendMgr) Init() {
this.friendHash = make(map[string]*map[string]int32) this.friendHash = make(map[string]map[string]int32)
this.blackHash = make(map[string]*map[string]int32) this.blackHash = make(map[string]map[string]int32)
this.byBlackHash = make(map[string]*map[string]int32) this.byBlackHash = make(map[string]map[string]int32)
this.loadFromDB() this.loadFromDB()
} }
@ -42,11 +42,15 @@ func (this *friendMgr) loadFriendships() {
} }
for ds.Next() { for ds.Next() {
idx := q5.ToInt64(ds.GetByName("idx")) idx := q5.ToInt64(ds.GetByName("idx"))
accountId1 := ds.GetByName("account_id1")
accountId2 := ds.GetByName("account_id2")
addTime := q5.ToInt32(ds.GetByName("add_time"))
if idx > lastIdx { if idx > lastIdx {
lastIdx = idx lastIdx = idx
} else { } else {
panic(fmt.Sprintf("friendMgr.loadFriendships idxerror:%s %s", idx, lastIdx)) panic(fmt.Sprintf("friendMgr.loadFriendships idxerror:%s %s", idx, lastIdx))
} }
this.addFriendShip(accountId1, accountId2, addTime)
} }
if ds.NumOfReaded() <= 0 { if ds.NumOfReaded() <= 0 {
done = true done = true
@ -124,7 +128,7 @@ func (this *friendMgr) GetBlackList(accountId string) []string {
func (this *friendMgr) getFriends(accountId string) *map[string]int32 { func (this *friendMgr) getFriends(accountId string) *map[string]int32 {
if friends, ok := this.friendHash[accountId]; ok { if friends, ok := this.friendHash[accountId]; ok {
return friends return &friends
} }
return nil return nil
} }
@ -156,3 +160,13 @@ func (this *friendMgr) AsyncAddBlack(senderId string, targetId string, cb func(i
func (this *friendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) { func (this *friendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) {
} }
func (this *friendMgr) addFriendShip(accountId1 string, accountId2 string, addTime int32) {
{
friends := this.getFriends(accountId1)
if friends != nil {
this.friendHash[accountId1] = make(map[string]int32)
friends = this.getFriends(accountId1)
}
}
}