orientation

This commit is contained in:
2024-11-07 07:55:31 +08:00
parent 0fef776ece
commit 08266046b8

View File

@@ -353,6 +353,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
}, },
}), }),
Args: graphql.FieldConfigArgument{ Args: graphql.FieldConfigArgument{
"orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选横屏竖屏图像"},
"follower": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的关注列表发布的图像"}, "follower": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的关注列表发布的图像"},
"interest": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的兴趣推荐图像"}, "interest": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的兴趣推荐图像"},
"similar": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取与指定ID图像相似的图像"}, "similar": &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取与指定ID图像相似的图像"},
@@ -388,6 +389,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
Interest int Interest int
Similar int Similar int
Follower int Follower int
Orientation string
} }
mapstructure.Decode(p.Args, &args) mapstructure.Decode(p.Args, &args)
@@ -475,7 +477,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
fmt.Println("Interest:", args.Interest) fmt.Println("Interest:", args.Interest)
} }
// 筛选: 关注列表 // 数据库中筛选: 关注列表
if args.Follower != 0 { if args.Follower != 0 {
// 返回JSON数组(2.5秒) // 返回JSON数组(2.5秒)
var item string var item string
@@ -495,27 +497,12 @@ func NewSchema(config Config) (graphql.Schema, error) {
sort.Slice(ids, func(i, j int) bool { sort.Slice(ids, func(i, j int) bool {
return ids[i] > ids[j] // 按照降序排列 return ids[i] > ids[j] // 按照降序排列
}) })
id_list = append(id_list, ids) id_list = append(id_list, ids)
}
//fmt.Println(item) // 数据库中筛选:横屏纵屏
if args.Orientation != "" {
// 返回所有结果(7秒) query.Where("article_orientation = ?", args.Orientation)
//var item []int
//if err := db.Table("web_fans").Select("web_images.id").Limit(10).Joins("inner join web_images on web_images.user_id = web_fans.blogger_id").Where("web_fans.follower_id = ?", 46).Pluck("id", &item).Error; err != nil {
// fmt.Println("获取关注列表失败", err)
// return nil, err
//}
// id_list = append(id_list, item)
// 直接出结果(最快)
//var q = db.Table("web_fans").Select("web_images.*").Limit(10)
//q = q.Joins("inner join web_images on web_images.user_id = web_fans.blogger_id")
//q = q.Where("web_fans.follower_id = ?", 46).Preload("User").Preload("Article").Find(&images)
//return map[string]interface{}{
// "list": images,
// "total": len(images),
//}, nil
} }
// 排序 // 排序