榜单字段
This commit is contained in:
10
README.md
10
README.md
@@ -65,6 +65,16 @@ CREATE INDEX idx_id_desc ON web_images (id DESC);
|
||||
-- 复合筛选降序索引 article_category_top_id
|
||||
CREATE INDEX idx_acti_id_desc ON web_images (article_category_top_id, id DESC);
|
||||
|
||||
-- 为 web_images 表的 color 设置复合索引用于筛选
|
||||
CREATE INDEX idx_color_0 ON web_images (color_0_r, color_0_g, color_0_b);
|
||||
CREATE INDEX idx_color_1 ON web_images (color_1_r, color_1_g, color_1_b);
|
||||
|
||||
-- 为 web_images 表的 day_rank 行设置倒序索引用于排序
|
||||
CREATE INDEX idx_day_rank_desc ON web_images (day_rank DESC);
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
|
16
api/image.go
16
api/image.go
@@ -46,6 +46,11 @@ type Image struct {
|
||||
Emoji4 int `json:"emoji4"`
|
||||
Emoji5 int `json:"emoji5"`
|
||||
Views int `json:"views"`
|
||||
DayRank int `json:"day_rank"`
|
||||
WeekRank int `json:"week_rank"`
|
||||
MonthRank int `json:"month_rank"`
|
||||
YearRank int `json:"year_rank"`
|
||||
AeonRank int `json:"aeon_rank"`
|
||||
}
|
||||
|
||||
func (Image) TableName() string {
|
||||
@@ -166,6 +171,11 @@ var imageType = graphql.NewObject(graphql.ObjectConfig{
|
||||
"emoji4": &graphql.Field{Type: graphql.Int, Description: "表情4数量"},
|
||||
"emoji5": &graphql.Field{Type: graphql.Int, Description: "表情5数量"},
|
||||
"views": &graphql.Field{Type: graphql.Int, Description: "浏览量"},
|
||||
"day_rank": &graphql.Field{Type: graphql.String, Description: "日榜"},
|
||||
"week_rank": &graphql.Field{Type: graphql.String, Description: "周榜"},
|
||||
"month_rank": &graphql.Field{Type: graphql.String, Description: "月榜"},
|
||||
"year_rank": &graphql.Field{Type: graphql.String, Description: "年榜"},
|
||||
"aeon_rank": &graphql.Field{Type: graphql.String, Description: "总榜"},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -564,6 +574,12 @@ var ImageItems = &graphql.Field{
|
||||
)).As("row_num"))
|
||||
}
|
||||
|
||||
//// 针对排行榜优化, 减少结果集
|
||||
//if p.Args["sort"] != nil && p.Args["sort"].(string) == "day_rank" {
|
||||
// fmt.Println("针对排行榜优化, 减少结果集 day_rank > 0")
|
||||
// query = query.Where(goqu.L("day_rank > 0"))
|
||||
//}
|
||||
|
||||
// 图像按点赞顺序排序 p.Args["sort"].(string) == "praise_time"
|
||||
if p.Args["praise"] != nil {
|
||||
query = query.Select("web_images.id", goqu.L(
|
||||
|
Reference in New Issue
Block a user