mirror of
https://git.fightbot.fun/hxuanyu/BingPaper.git
synced 2026-02-15 14:49:34 +08:00
优化每日图片查询逻辑,使用数据库查询替代循环调用获取多地区图片
This commit is contained in:
@@ -115,19 +115,19 @@ func GetTodayImage(mkt string) (*model.ImageRegion, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetAllRegionsTodayImages() ([]model.ImageRegion, error) {
|
func GetAllRegionsTodayImages() ([]model.ImageRegion, error) {
|
||||||
|
today := time.Now().Format("2006-01-02")
|
||||||
regions := config.GetConfig().Fetcher.Regions
|
regions := config.GetConfig().Fetcher.Regions
|
||||||
if len(regions) == 0 {
|
if len(regions) == 0 {
|
||||||
regions = []string{config.GetConfig().GetDefaultRegion()}
|
regions = []string{config.GetConfig().GetDefaultRegion()}
|
||||||
}
|
}
|
||||||
|
|
||||||
var images []model.ImageRegion
|
var images []model.ImageRegion
|
||||||
for _, mkt := range regions {
|
err := repo.DB.Where("date = ? AND mkt IN ?", today, regions).
|
||||||
img, err := GetTodayImage(mkt)
|
Preload("Variants", func(db *gorm.DB) *gorm.DB {
|
||||||
if err == nil {
|
return db.Order("size asc")
|
||||||
images = append(images, *img)
|
}).Find(&images).Error
|
||||||
}
|
|
||||||
}
|
return images, err
|
||||||
return images, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRandomImage(mkt string) (*model.ImageRegion, error) {
|
func GetRandomImage(mkt string) (*model.ImageRegion, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user