🔥 remove debug info in gorm

This commit is contained in:
源文雨 2022-04-16 00:04:07 +08:00
parent dfd184724b
commit c76d9d4461
6 changed files with 53 additions and 53 deletions

View File

@ -55,7 +55,7 @@ func initialize(dbpath string) (*vupdb, error) {
if err != nil {
return nil, err
}
gdb.Debug().AutoMigrate(&vup{}).AutoMigrate(&config{})
gdb.AutoMigrate(&vup{}).AutoMigrate(&config{})
return (*vupdb)(gdb), nil
}
@ -66,9 +66,9 @@ func (vdb *vupdb) insertVupByMid(mid int64, uname string, roomid int64) (err err
Uname: uname,
Roomid: roomid,
}
if err = db.Debug().Model(&vup{}).First(&v, "mid = ? ", mid).Error; err != nil {
if err = db.Model(&vup{}).First(&v, "mid = ? ", mid).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&vup{}).Create(&v).Error
err = db.Model(&vup{}).Create(&v).Error
}
}
return
@ -77,7 +77,7 @@ func (vdb *vupdb) insertVupByMid(mid int64, uname string, roomid int64) (err err
// filterVup 筛选vup
func (vdb *vupdb) filterVup(ids []int64) (vups []vup, err error) {
db := (*gorm.DB)(vdb)
if err = db.Debug().Model(&vup{}).Find(&vups, "mid in (?)", ids).Error; err != nil {
if err = db.Model(&vup{}).Find(&vups, "mid in (?)", ids).Error; err != nil {
return vups, err
}
return
@ -112,13 +112,13 @@ func (vdb *vupdb) setBilibiliCookie(cookie string) (err error) {
Key: bilibiliCookie,
Value: cookie,
}
if err = db.Debug().Model(&config{}).First(&c, "key = ? ", bilibiliCookie).Error; err != nil {
if err = db.Model(&config{}).First(&c, "key = ? ", bilibiliCookie).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&config{}).Create(&c).Error
err = db.Model(&config{}).Create(&c).Error
}
} else {
err = db.Debug().Model(&config{}).Where("key = ? ", bilibiliCookie).Update(
err = db.Model(&config{}).Where("key = ? ", bilibiliCookie).Update(
map[string]interface{}{
"value": cookie,
}).Error
@ -128,6 +128,6 @@ func (vdb *vupdb) setBilibiliCookie(cookie string) (err error) {
func (vdb *vupdb) getBilibiliCookie() (c config) {
db := (*gorm.DB)(vdb)
db.Debug().Model(&config{}).First(&c, "key = ?", bilibiliCookie)
db.Model(&config{}).First(&c, "key = ?", bilibiliCookie)
return
}

View File

@ -59,12 +59,12 @@ func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interfa
bp := bilibilipush{}
data, _ := json.Marshal(&bpMap)
_ = json.Unmarshal(data, &bp)
if err = db.Debug().Model(&bilibilipush{}).First(&bp, "bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Error; err != nil {
if err = db.Model(&bilibilipush{}).First(&bp, "bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&bilibilipush{}).Create(&bp).Error
err = db.Model(&bilibilipush{}).Create(&bp).Error
}
} else {
err = db.Debug().Model(&bilibilipush{}).Where("bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Update(bpMap).Error
err = db.Model(&bilibilipush{}).Where("bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Update(bpMap).Error
}
return
}
@ -72,7 +72,7 @@ func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interfa
func (bdb *bilibilipushdb) getAllBuidByLive() (buidList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "live_disable = 0")
db.Model(&bilibilipush{}).Find(&bpl, "live_disable = 0")
temp := make(map[int64]bool)
for _, v := range bpl {
_, ok := temp[v.BilibiliUID]
@ -87,7 +87,7 @@ func (bdb *bilibilipushdb) getAllBuidByLive() (buidList []int64) {
func (bdb *bilibilipushdb) getAllBuidByDynamic() (buidList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "dynamic_disable = 0")
db.Model(&bilibilipush{}).Find(&bpl, "dynamic_disable = 0")
temp := make(map[int64]bool)
for _, v := range bpl {
_, ok := temp[v.BilibiliUID]
@ -102,7 +102,7 @@ func (bdb *bilibilipushdb) getAllBuidByDynamic() (buidList []int64) {
func (bdb *bilibilipushdb) getAllGroupByBuidAndLive(buid int64) (groupList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and live_disable = 0", buid)
db.Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and live_disable = 0", buid)
for _, v := range bpl {
groupList = append(groupList, v.GroupID)
}
@ -112,7 +112,7 @@ func (bdb *bilibilipushdb) getAllGroupByBuidAndLive(buid int64) (groupList []int
func (bdb *bilibilipushdb) getAllGroupByBuidAndDynamic(buid int64) (groupList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and dynamic_disable = 0", buid)
db.Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and dynamic_disable = 0", buid)
for _, v := range bpl {
groupList = append(groupList, v.GroupID)
}
@ -121,7 +121,7 @@ func (bdb *bilibilipushdb) getAllGroupByBuidAndDynamic(buid int64) (groupList []
func (bdb *bilibilipushdb) getAllPushByGroup(groupID int64) (bpl []bilibilipush) {
db := (*gorm.DB)(bdb)
db.Debug().Model(&bilibilipush{}).Find(&bpl, "group_id = ? and (live_disable = 0 or dynamic_disable = 0)", groupID)
db.Model(&bilibilipush{}).Find(&bpl, "group_id = ? and (live_disable = 0 or dynamic_disable = 0)", groupID)
return
}
@ -131,13 +131,13 @@ func (bdb *bilibilipushdb) insertBilibiliUp(buid int64, name string) {
BilibiliUID: buid,
Name: name,
}
db.Debug().Model(&bilibiliup{}).Create(bu)
db.Model(&bilibiliup{}).Create(bu)
}
func (bdb *bilibilipushdb) updateAllUp() {
db := (*gorm.DB)(bdb)
var bul []bilibiliup
db.Debug().Model(&bilibiliup{}).Find(&bul)
db.Model(&bilibiliup{}).Find(&bul)
for _, v := range bul {
upMap[v.BilibiliUID] = v.Name
}

View File

@ -65,7 +65,7 @@ func (sdb *scoredb) Close() error {
// GetScoreByUID 取得分数
func (sdb *scoredb) GetScoreByUID(uid int64) (s scoretable) {
db := (*gorm.DB)(sdb)
db.Debug().Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
db.Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
return s
}
@ -76,13 +76,13 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
UID: uid,
Score: score,
}
if err = db.Debug().Model(&scoretable{}).First(&s, "uid = ? ", uid).Error; err != nil {
if err = db.Model(&scoretable{}).First(&s, "uid = ? ", uid).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&scoretable{}).Create(&s).Error // newUser not user
err = db.Model(&scoretable{}).Create(&s).Error // newUser not user
}
} else {
err = db.Debug().Model(&scoretable{}).Where("uid = ? ", uid).Update(
err = db.Model(&scoretable{}).Where("uid = ? ", uid).Update(
map[string]interface{}{
"score": score,
}).Error
@ -93,7 +93,7 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
// GetSignInByUID 取得签到次数
func (sdb *scoredb) GetSignInByUID(uid int64) (si signintable) {
db := (*gorm.DB)(sdb)
db.Debug().Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
db.Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
return si
}
@ -104,13 +104,13 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
UID: uid,
Count: count,
}
if err = db.Debug().Model(&signintable{}).First(&si, "uid = ? ", uid).Error; err != nil {
if err = db.Model(&signintable{}).First(&si, "uid = ? ", uid).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&signintable{}).Create(&si) // newUser not user
db.Model(&signintable{}).Create(&si) // newUser not user
}
} else {
err = db.Debug().Model(&signintable{}).Where("uid = ? ", uid).Update(
err = db.Model(&signintable{}).Where("uid = ? ", uid).Update(
map[string]interface{}{
"count": count,
}).Error
@ -120,6 +120,6 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
func (sdb *scoredb) GetScoreRankByTopN(n int) (st []scoretable, err error) {
db := (*gorm.DB)(sdb)
err = db.Debug().Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
return
}

View File

@ -68,20 +68,20 @@ func (sdb *sleepdb) sleep(gid, uid int64) (position int, awakeTime time.Duration
UserID: uid,
SleepTime: now,
}
if err := db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
if err := db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
db.Model(&SleepManage{}).Create(&st) // newUser not user
}
} else {
log.Debugln("sleeptime为", st)
awakeTime = now.Sub(st.SleepTime)
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
map[string]interface{}{
"sleep_time": now,
})
}
db.Debug().Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
db.Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
return position, awakeTime
}
@ -95,19 +95,19 @@ func (sdb *sleepdb) getUp(gid, uid int64) (position int, sleepTime time.Duration
UserID: uid,
SleepTime: now,
}
if err := db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
if err := db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
db.Model(&SleepManage{}).Create(&st) // newUser not user
}
} else {
log.Debugln("sleeptime为", st)
sleepTime = now.Sub(st.SleepTime)
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
map[string]interface{}{
"sleep_time": now,
})
}
db.Debug().Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
db.Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
return position, sleepTime
}

View File

@ -99,7 +99,7 @@ func (vdb *VtbDB) GetAllFirstCategoryMessage() (string, error) {
db := (*gorm.DB)(vdb)
firstStepMessage := "请选择一个vtb并发送序号:\n"
var fcl []FirstCategory
err := db.Debug().Model(&FirstCategory{}).Find(&fcl).Error
err := db.Model(&FirstCategory{}).Find(&fcl).Error
if err != nil {
return "", err
}
@ -116,7 +116,7 @@ func (vdb *VtbDB) GetAllSecondCategoryMessageByFirstIndex(firstIndex int) (strin
var scl []SecondCategory
var fc FirstCategory
db.Model(FirstCategory{}).Where("first_category_index = ?", firstIndex).First(&fc)
err := db.Debug().Model(&SecondCategory{}).Find(&scl, "first_category_uid = ?", fc.FirstCategoryUID).Error
err := db.Model(&SecondCategory{}).Find(&scl, "first_category_uid = ?", fc.FirstCategoryUID).Error
if err != nil || len(scl) == 0 {
return "", err
}
@ -133,7 +133,7 @@ func (vdb *VtbDB) GetAllThirdCategoryMessageByFirstIndexAndSecondIndex(firstInde
var fc FirstCategory
db.Model(FirstCategory{}).Where("first_category_index = ?", firstIndex).First(&fc)
var tcl []ThirdCategory
err := db.Debug().Model(&ThirdCategory{}).Find(&tcl, "first_category_uid = ? and second_category_index = ?", fc.FirstCategoryUID, secondIndex).Error
err := db.Model(&ThirdCategory{}).Find(&tcl, "first_category_uid = ? and second_category_index = ?", fc.FirstCategoryUID, secondIndex).Error
if err != nil || len(tcl) == 0 {
return "", err
}
@ -217,12 +217,12 @@ func (vdb *VtbDB) GetVtbList() (uidList []string, err error) {
}
log.Debugln(fc)
if err := db.Debug().Model(&FirstCategory{}).First(&fc, "first_category_uid = ?", fc.FirstCategoryUID).Error; err != nil {
if err := db.Model(&FirstCategory{}).First(&fc, "first_category_uid = ?", fc.FirstCategoryUID).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&FirstCategory{}).Create(&fc) // newUser not user
db.Model(&FirstCategory{}).Create(&fc) // newUser not user
}
} else {
db.Debug().Model(&FirstCategory{}).Where("first_category_uid = ?", fc.FirstCategoryUID).Update(
db.Model(&FirstCategory{}).Where("first_category_uid = ?", fc.FirstCategoryUID).Update(
map[string]interface{}{
"first_category_index": i,
"first_category_name": item.Get("name").String(),
@ -276,13 +276,13 @@ func (vdb *VtbDB) StoreVtb(uid string) (err error) {
FirstCategoryUID: uid,
}
if err := db.Debug().Model(&SecondCategory{}).First(&sc, "first_category_uid = ? and second_category_index = ?", uid, secondIndex).Error; err != nil {
if err := db.Model(&SecondCategory{}).First(&sc, "first_category_uid = ? and second_category_index = ?", uid, secondIndex).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SecondCategory{}).Create(&sc) // newUser not user
db.Model(&SecondCategory{}).Create(&sc) // newUser not user
}
} else {
db.Debug().Model(&SecondCategory{}).Where("first_category_uid = ? and second_category_index = ?", uid, secondIndex).Update(
db.Model(&SecondCategory{}).Where("first_category_uid = ? and second_category_index = ?", uid, secondIndex).Update(
map[string]interface{}{
"second_category_name": secondItem.Get("categoryName").String(),
"second_category_author": secondItem.Get("author").String(),
@ -305,13 +305,13 @@ func (vdb *VtbDB) StoreVtb(uid string) (err error) {
}
log.Debugln(tc)
if err := db.Debug().Model(&ThirdCategory{}).First(&tc, "first_category_uid = ? and second_category_index = ? and third_category_index = ?",
if err := db.Model(&ThirdCategory{}).First(&tc, "first_category_uid = ? and second_category_index = ? and third_category_index = ?",
uid, secondIndex, thirdIndex).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&ThirdCategory{}).Create(&tc) // newUser not user
db.Model(&ThirdCategory{}).Create(&tc) // newUser not user
}
} else {
db.Debug().Model(&ThirdCategory{}).Where("first_category_uid = ? and second_category_index = ? and third_category_index = ?",
db.Model(&ThirdCategory{}).Where("first_category_uid = ? and second_category_index = ? and third_category_index = ?",
uid, secondIndex, thirdIndex).Update(
map[string]interface{}{
"third_category_name": thirdItem.Get("name").String(),

View File

@ -64,12 +64,12 @@ func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictur
PictureDescription: pictureDescription,
PictureList: pictureList,
}
if err = db.Debug().Model(&ymgal{}).First(&y, "id = ? ", id).Error; err != nil {
if err = db.Model(&ymgal{}).First(&y, "id = ? ", id).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&ymgal{}).Create(&y).Error // newUser not user
err = db.Model(&ymgal{}).Create(&y).Error // newUser not user
}
} else {
err = db.Debug().Model(&ymgal{}).Where("id = ? ", id).Update(map[string]interface{}{
err = db.Model(&ymgal{}).Where("id = ? ", id).Update(map[string]interface{}{
"title": title,
"picture_type": pictureType,
"picture_description": pictureDescription,
@ -81,14 +81,14 @@ func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictur
func (gdb *ymgaldb) getYmgalByID(id string) (y ymgal) {
db := (*gorm.DB)(gdb)
db.Debug().Model(&ymgal{}).Where("id = ?", id).Take(&y)
db.Model(&ymgal{}).Where("id = ?", id).Take(&y)
return
}
func (gdb *ymgaldb) randomYmgal(pictureType string) (y ymgal) {
db := (*gorm.DB)(gdb)
var count int
s := db.Debug().Model(&ymgal{}).Where("picture_type = ?", pictureType).Count(&count)
s := db.Model(&ymgal{}).Where("picture_type = ?", pictureType).Count(&count)
if count == 0 {
return
}
@ -99,7 +99,7 @@ func (gdb *ymgaldb) randomYmgal(pictureType string) (y ymgal) {
func (gdb *ymgaldb) getYmgalByKey(pictureType, key string) (y ymgal) {
db := (*gorm.DB)(gdb)
var count int
s := db.Debug().Model(&ymgal{}).Where("picture_type = ? and (picture_description like ? or title like ?) ", pictureType, "%"+key+"%", "%"+key+"%").Count(&count)
s := db.Model(&ymgal{}).Where("picture_type = ? and (picture_description like ? or title like ?) ", pictureType, "%"+key+"%", "%"+key+"%").Count(&count)
if count == 0 {
return
}