This commit is contained in:
殷勇 2023-10-27 15:25:18 +08:00
parent ba7a99d362
commit b0f7b10a02
4 changed files with 9 additions and 7 deletions

View File

@ -85,7 +85,7 @@ func (m *Mail) IsReadableMail(accountObj common.Player) bool {
}
}
nowUnixSec := int32(time.Now().Unix())
if m.ExpireTime > nowUnixSec && m.SendTime <= nowUnixSec && !accountObj.IsDeletedMail(m.MailId) {
if m.ExpireTime > nowUnixSec && m.SendTime <= nowUnixSec && accountObj.IsUnreadMail(m.MailId) {
return true
}

View File

@ -66,7 +66,6 @@ func (mm *MailMgr) GetMails(player common.Player) []*Mail {
resMailList = append(resMailList, pMail)
}
}
return resMailList
}

View File

@ -45,8 +45,8 @@ func (p *Player) GetRegisterTime() int32 {
}
func (p *Player) IsUnreadMail(mailId int64) bool {
m := p.ReadMailHash[mailId]
return m == nil
_, exists := p.ReadMailHash[mailId]
return !exists
}
func (p *Player) IsDeletedMail(mailId int64) bool {
@ -72,7 +72,6 @@ func (p *Player) MarkMail(mailIds string) {
}
}
p.MarkDirty()
// p.SaveToDB()
}
func (p *Player) DeleteMails(mailIds string) {
@ -186,7 +185,7 @@ func (p *Player) Serialize(accountPB *ss.MFAccountData) {
}
func (p *Player) UpdateExpire() {
p.CacheExpiration = time.Now().Add(10 * time.Second)
p.CacheExpiration = time.Now().Add(20 * time.Second)
}
func (p *Player) IsCacheExpired() bool {
@ -216,6 +215,8 @@ func (p *Player) SaveToDB() {
if err != nil {
f5.GetSysLog().Info("SaveToDB Error:%v\n", err)
} else {
// 标记p 为已过期
p.CacheExpiration = time.Now().Add(-10 * time.Second)
f5.GetSysLog().Info("SaveToDB OK\n")
}
},

View File

@ -1,6 +1,7 @@
package player
import (
"f5"
"sync"
)
@ -29,6 +30,7 @@ func (pm *PlayerMgr) GetPlayer(accountId string) *Player {
func (pm *PlayerMgr) AsyncGetPlayer(accountId string) *Player {
p := pm.GetPlayer(accountId)
if p != nil && !p.IsCacheExpired() {
f5.GetSysLog().Info("GetPlayer(%s) from cache", accountId)
return p
}
@ -39,7 +41,7 @@ func (pm *PlayerMgr) AsyncGetPlayer(accountId string) *Player {
go func(accountId string) {
pm.LoadPlayer(accountId, func(err error, p *Player) {
defer wg.Done()
if err != nil && p != nil {
if err == nil && p != nil {
player = p
pm.accountIdHash[p.GetAccountId()] = p
}