optimize updates

This commit is contained in:
mubai
2025-03-23 16:30:56 +08:00
parent c1e28380d0
commit 24aa240ab2
40 changed files with 1088 additions and 590 deletions

View File

@@ -45,11 +45,26 @@ func (i *IndexLogic) IndexPage() map[string]interface{} {
// 2. 提供用于首页展示的顶级分类影片信息, 每分类 14条数据
var list []map[string]interface{}
for _, c := range tree.Children {
// 生成分页参数
page := system.Page{PageSize: 14, Current: 1}
movies := system.GetMovieListByPid(c.Id, &page)
// 获取当前分类的本月热门影片
HotMovies := system.GetHotMovieByPid(c.Id, &page)
item := map[string]interface{}{"nav": c, "movies": movies, "hot": HotMovies}
// 获取最近上映影片和本月热门影片
var movies []system.MovieBasicInfo
var hotMovies []system.SearchInfo
if c.Children != nil {
// 如果有子分类, 则通过Pid获取对应影片
// 获取当前分类的最新上映影片
movies = system.GetMovieListByPid(c.Id, &page)
// 获取当前分类的本月热门影片
hotMovies = system.GetHotMovieByPid(c.Id, &page)
} else {
// 如果当前分类为一级分类且没有子分类,则通过Cid获取对应数据
// 获取当前分类的最新上映影片
movies = system.GetMovieListByCid(c.Id, &page)
// 获取当前分类的本月热门影片
hotMovies = system.GetHotMovieByCid(c.Id, &page)
}
item := map[string]interface{}{"nav": c, "movies": movies, "hot": hotMovies}
list = append(list, item)
}
Info["content"] = list

View File

@@ -7,11 +7,12 @@ import (
"server/plugin/SystemInit"
"server/plugin/db"
"server/router"
"time"
)
func init() {
// 执行初始化前等待20s , 让mysql服务完成初始化指令
//time.Sleep(time.Second * 20)
time.Sleep(time.Second * 20)
//初始化redis客户端
err := db.InitRedisConn()
if err != nil {

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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)

View File

@@ -29,6 +29,9 @@ func FilmSourceInit() {
{Id: util.GenerateSalt(), Name: "HD(LY)", Uri: `https://360zy.com/api.php/provide/vod/at/json`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
{Id: util.GenerateSalt(), Name: "HD(SN)", Uri: `https://suoniapi.com/api.php/provide/vod/from/snm3u8/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false, Interval: 2000},
{Id: util.GenerateSalt(), Name: "HD(DB)", Uri: `https://caiji.dbzy.tv/api.php/provide/vod/from/dbm3u8/at/josn/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
{Id: util.GenerateSalt(), Name: "HD(IK)", Uri: `https://ikunzyapi.com/api.php/provide/vod/at/json`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
//{Id: util.GenerateSalt(), Name: "WX(T2)", Uri: `https://api.wuxianzy.net/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
//{Id: util.GenerateSalt(), Name: "OK(BK)", Uri: `https://api.okzy.org/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
//{Id: util.GenerateSalt(), Name: "HD(HW)", Uri: `https://cjhwba.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false, Interval: 3000},
//{Id: util.GenerateSalt(), Name: "HD(lzBk)", Uri: `https://cj.lzcaiji.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},
//{Id: util.GenerateSalt(), Name: "HD(fs)", Uri: `https://www.feisuzyapi.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: false},

View File

@@ -3,6 +3,7 @@ package db
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"server/config"
)
@@ -24,7 +25,7 @@ func InitMysql() (err error) {
SingularTable: true, //是否使用 结构体名称作为表名 (关闭自动变复数)
//NameReplacer: strings.NewReplacer("spider_", ""), // 替表名和字段中的 Me 为 空
},
//Logger: logger.Default.LogMode(logger.Info), //设置日志级别为Info
Logger: logger.Default.LogMode(logger.Info), //设置日志级别为Info
})
return
}