From 08e7eddaa5fa578a873c32a8d1d428fac6af3005 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 6 May 2024 14:49:08 +0800 Subject: [PATCH] 1 --- server/mailserver/mail/mailmgr.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go index 6b28c7c8..e95c0167 100644 --- a/server/mailserver/mail/mailmgr.go +++ b/server/mailserver/mail/mailmgr.go @@ -22,6 +22,7 @@ type mailMgr struct { personalMails sync.Map //string => sync.Map groupHash sync.Map //int64 => *userGroup lastSyncEventIdx int64 + pullingEvent bool } func (this *mailMgr) Init() { @@ -283,4 +284,30 @@ func (this *mailMgr) syncEvent() { panic("sync event error") } }); + f5.GetTimer().SetInterval( + 1000 * 2, + func (e int32, args *q5.Args) { + if e == q5.TIMER_EXEC_EVENT { + this.pullEvent() + } + }) +} + +func (this *mailMgr) pullEvent() { + if this.pullingEvent { + return + } + this.pullingEvent = true + f5.GetJsStyleDb().SyncSelectCustomQuery( + constant.MAIL_DB, + fmt.Sprintf("SELECT * FROM t_event WHERE idx > %d;", this.lastSyncEventIdx), + func(err error, ds *f5.DataSet) { + this.pullingEvent = false + if err != nil { + return + } + for ds.Next() { + this.lastSyncEventIdx = q5.ToInt64(ds.GetByName("idx")) + } + }) }