parent
a08aeee0c2
commit
b729cac998
@ -1,42 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db"
|
||||
"fmt"
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//for {
|
||||
// fmt.Println("start delete mongodb expired record")
|
||||
// timeUnixBegin := time.Now().Unix()
|
||||
// count, _ := db.DB.MgoUserCount()
|
||||
// fmt.Println("mongodb record count: ", count)
|
||||
// for i := 0; i < count; i++ {
|
||||
// time.Sleep(1 * time.Millisecond)
|
||||
// uid, _ := db.DB.MgoSkipUID(i)
|
||||
// fmt.Println("operate uid: ", uid)
|
||||
// err := db.DB.DelUserChat(uid)
|
||||
// if err != nil {
|
||||
// fmt.Println("operate uid failed: ", uid, err.Error())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// timeUnixEnd := time.Now().Unix()
|
||||
// costTime := timeUnixEnd - timeUnixBegin
|
||||
// if costTime > int64(config.Config.Mongo.DBRetainChatRecords*24*3600) {
|
||||
// continue
|
||||
// } else {
|
||||
// sleepTime := 0
|
||||
// if int64(config.Config.Mongo.DBRetainChatRecords*24*3600)-costTime > 24*3600 {
|
||||
// sleepTime = 24 * 3600
|
||||
// } else {
|
||||
// sleepTime = config.Config.Mongo.DBRetainChatRecords*24*3600 - int(costTime)
|
||||
// }
|
||||
// fmt.Println("sleep: ", sleepTime)
|
||||
// time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
// }
|
||||
//}
|
||||
for {
|
||||
fmt.Println("start delete mongodb expired record")
|
||||
timeUnixBegin := time.Now().Unix()
|
||||
count, _ := db.DB.MgoUserCount()
|
||||
fmt.Println("mongodb record count: ", count)
|
||||
for i := 0; i < count; i++ {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
uid, _ := db.DB.MgoSkipUID(i)
|
||||
fmt.Println("operate uid: ", uid)
|
||||
err := db.DB.DelUserChat(uid)
|
||||
uidList, err := im_mysql_model.SelectAllUID()
|
||||
if err != nil {
|
||||
fmt.Println("operate uid failed: ", uid, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
timeUnixEnd := time.Now().Unix()
|
||||
costTime := timeUnixEnd - timeUnixBegin
|
||||
if costTime > int64(config.Config.Mongo.DBRetainChatRecords*24*3600) {
|
||||
continue
|
||||
log.NewError("999999", err.Error())
|
||||
} else {
|
||||
sleepTime := 0
|
||||
if int64(config.Config.Mongo.DBRetainChatRecords*24*3600)-costTime > 24*3600 {
|
||||
sleepTime = 24 * 3600
|
||||
for _, v := range uidList {
|
||||
minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||
if err != nil {
|
||||
log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||
continue
|
||||
} else {
|
||||
sleepTime = config.Config.Mongo.DBRetainChatRecords*24*3600 - int(costTime)
|
||||
err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||
if err != nil {
|
||||
log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||
}
|
||||
}
|
||||
fmt.Println("sleep: ", sleepTime)
|
||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue