mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-14 22:44:43 +08:00
optimize updates
This commit is contained in:
@@ -39,8 +39,18 @@ func CreateFailureRecordTable() {
|
||||
|
||||
// SaveFailureRecord 添加采集失效记录
|
||||
func SaveFailureRecord(fl FailureRecord) {
|
||||
if err := db.Mdb.Create(&fl).Error; err != nil {
|
||||
log.Println("Add failure record failed:", err)
|
||||
// 数据量不多但存在并发问题, 开启事务
|
||||
err := db.Mdb.Transaction(func(tx *gorm.DB) error {
|
||||
// 将采集失败信息存储到record表中
|
||||
if err := tx.Create(&fl).Error; err != nil {
|
||||
log.Println("Add failure record failed:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// 如果事务提交失败, 则输出相应信息, (存一份数据到Redis??)
|
||||
if err != nil {
|
||||
log.Println("Save failure record affairs failed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ func GetMovieListByCid(cid int64, page *Page) []MovieBasicInfo {
|
||||
return list
|
||||
}
|
||||
|
||||
// GetHotMovieByPid 获取指定类别的热门影片
|
||||
// GetHotMovieByPid 获取Pid指定类别的热门影片
|
||||
func GetHotMovieByPid(pid int64, page *Page) []SearchInfo {
|
||||
// 返回分页参数
|
||||
//var count int64
|
||||
@@ -453,6 +453,24 @@ func GetHotMovieByPid(pid int64, page *Page) []SearchInfo {
|
||||
return s
|
||||
}
|
||||
|
||||
// GetHotMovieByCid 获取当前分类下的热门影片
|
||||
func GetHotMovieByCid(cid int64, page *Page) []SearchInfo {
|
||||
// 返回分页参数
|
||||
//var count int64
|
||||
//db.Mdb.Model(&SearchInfo{}).Where("pid", pid).Count(&count)
|
||||
//page.Total = int(count)
|
||||
//page.PageCount = int((page.Total + page.PageSize - 1) / page.PageSize)
|
||||
// 进行具体的信息查询
|
||||
var s []SearchInfo
|
||||
// 当前时间偏移一个月
|
||||
t := time.Now().AddDate(0, -1, 0).Unix()
|
||||
if err := db.Mdb.Limit(page.PageSize).Offset((page.Current-1)*page.PageSize).Where("cid=? AND update_stamp > ?", cid, t).Order(" year DESC, hits DESC").Find(&s).Error; err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// SearchFilmKeyword 通过关键字搜索库存中满足条件的影片名
|
||||
func SearchFilmKeyword(keyword string, page *Page) []SearchInfo {
|
||||
var searchList []SearchInfo
|
||||
|
||||
@@ -36,7 +36,7 @@ func CreateUserTable() {
|
||||
// 如果不存在则创建表 并设置自增ID初始值为10000
|
||||
if !ExistUserTable() {
|
||||
err := db.Mdb.AutoMigrate(u)
|
||||
db.Mdb.Exec(fmt.Sprintf("alter table %s auto_Increment = %s", u.TableName(), config.UserIdInitialVal))
|
||||
db.Mdb.Exec(fmt.Sprintf("alter table %s auto_Increment = %d", u.TableName(), config.UserIdInitialVal))
|
||||
if err != nil {
|
||||
log.Println("Create Table SearchInfo Failed: ", err)
|
||||
}
|
||||
@@ -81,6 +81,7 @@ func GetUserByNameOrEmail(userName string) *User {
|
||||
return u
|
||||
}
|
||||
|
||||
// GetUserById 通过id获取对应的用户信息
|
||||
func GetUserById(id uint) User {
|
||||
var user = User{Model: gorm.Model{ID: id}}
|
||||
db.Mdb.First(&user)
|
||||
|
||||
Reference in New Issue
Block a user