减少传输耗时
This commit is contained in:
@@ -45,8 +45,8 @@ CREATE FULLTEXT INDEX idx_tags ON web_images (tags);
|
|||||||
CREATE FULLTEXT INDEX idx_tags ON web_article (tags);
|
CREATE FULLTEXT INDEX idx_tags ON web_article (tags);
|
||||||
|
|
||||||
-- 同步收藏
|
-- 同步收藏
|
||||||
ALTER TABLE web_praise ADD COLUMN gorse TINYINT UNSIGNED;
|
ALTER TABLE web_praise ADD COLUMN gorse BOOLEAN DEFAULT FALSE;
|
||||||
|
ALTER TABLE web_praise ADD COLUMN gorse BOOLEAN DEFAULT FALSE;
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
11
api/gorse.go
11
api/gorse.go
@@ -62,11 +62,12 @@ func PutPraises(page int) error {
|
|||||||
CreateTime time.Time
|
CreateTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.Table("web_praises").Select("id", "praise_id", "user_id", "create_time").Where("type = ?", 4).Limit(100).Offset(i * 100).Scan(&data).Error; err != nil {
|
if err := db.Table("web_praise").Select("id", "praise_id", "user_id", "create_time").Where("gorse = false").Where("type = ?", 4).Limit(100).Scan(&data).Error; err != nil {
|
||||||
fmt.Println("获取点赞记录失败", err)
|
fmt.Println("获取图像点赞记录失败", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ids []int
|
||||||
for _, item := range data {
|
for _, item := range data {
|
||||||
fmt.Println(item.ID, item.UserID, item.PraiseID, item.CreateTime)
|
fmt.Println(item.ID, item.UserID, item.PraiseID, item.CreateTime)
|
||||||
feedbacks = append(feedbacks, client.Feedback{
|
feedbacks = append(feedbacks, client.Feedback{
|
||||||
@@ -75,6 +76,12 @@ func PutPraises(page int) error {
|
|||||||
ItemId: fmt.Sprintf("%d", item.PraiseID),
|
ItemId: fmt.Sprintf("%d", item.PraiseID),
|
||||||
Timestamp: item.CreateTime.Format("2006-01-02 15:04:05"),
|
Timestamp: item.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
})
|
})
|
||||||
|
ids = append(ids, item.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Table("web_praise").Where("id in (?)", data).Update("gorse", true).Error; err != nil {
|
||||||
|
fmt.Println("更新点赞记录失败", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := gorse.InsertFeedback(ctx, feedbacks); err != nil {
|
if _, err := gorse.InsertFeedback(ctx, feedbacks); err != nil {
|
||||||
|
@@ -598,10 +598,9 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"sort": []string{
|
"_source": false,
|
||||||
"_score",
|
"sort": []string{"_score"},
|
||||||
},
|
"size": 100000,
|
||||||
"size": 2000,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -621,7 +620,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query = query.Where(goqu.Ex{"web_images.id": goqu.Op{"in": item}}).Select("web_images.id", goqu.L(
|
query = query.Where(goqu.Ex{"web_images.id": goqu.Op{"in": item}}).Select("web_images.id", goqu.L(
|
||||||
//fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY FIELD(%s, %s))", "web_images.id", regexp.MustCompile(`[\[\]]`).ReplaceAllString(strings.Join(strings.Fields(fmt.Sprint(item)), ", "), "")),
|
|
||||||
fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY %s %s)", "web_images.id", "DESC"),
|
fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY %s %s)", "web_images.id", "DESC"),
|
||||||
).As("row_num"))
|
).As("row_num"))
|
||||||
}
|
}
|
||||||
@@ -886,7 +884,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
limit = args.Last
|
limit = args.Last
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("SQL:", sql)
|
//fmt.Println("SQL:", sql)
|
||||||
|
|
||||||
sql = fmt.Sprintf(`
|
sql = fmt.Sprintf(`
|
||||||
WITH RankedArticles AS (%s)
|
WITH RankedArticles AS (%s)
|
||||||
@@ -896,7 +894,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
ORDER BY LimitedRanked.row_num LIMIT %d
|
ORDER BY LimitedRanked.row_num LIMIT %d
|
||||||
`, sql, cursor, limit)
|
`, sql, cursor, limit)
|
||||||
|
|
||||||
fmt.Println("cursor:", cursor, limit)
|
//fmt.Println("cursor:", cursor, limit)
|
||||||
|
|
||||||
if err := db.Raw(sql).Scan(&images).Error; err != nil {
|
if err := db.Raw(sql).Scan(&images).Error; err != nil {
|
||||||
fmt.Println("获取图像列表失败", err)
|
fmt.Println("获取图像列表失败", err)
|
||||||
@@ -909,8 +907,8 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var find = db.Where("web_images.id IN ?", ids)
|
var find = db.Where("web_images.id IN ?", ids)
|
||||||
for index, item := range LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections) {
|
for _, item := range LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections) {
|
||||||
fmt.Println(index, item)
|
//fmt.Println(index, item)
|
||||||
find = find.Preload(item)
|
find = find.Preload(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,19 +47,19 @@ type Response struct {
|
|||||||
ID string `json:"_id"`
|
ID string `json:"_id"`
|
||||||
Score float64 `json:"_score"`
|
Score float64 `json:"_score"`
|
||||||
Timestamp string `json:"@timestamp"`
|
Timestamp string `json:"@timestamp"`
|
||||||
Source struct {
|
//Source struct {
|
||||||
Timestamp string `json:"@timestamp"`
|
// Timestamp string `json:"@timestamp"`
|
||||||
Athlete string `json:"Athlete"`
|
// Athlete string `json:"Athlete"`
|
||||||
City string `json:"City"`
|
// City string `json:"City"`
|
||||||
Country string `json:"Country"`
|
// Country string `json:"Country"`
|
||||||
Discipline string `json:"Discipline"`
|
// Discipline string `json:"Discipline"`
|
||||||
Event string `json:"Event"`
|
// Event string `json:"Event"`
|
||||||
Gender string `json:"Gender"`
|
// Gender string `json:"Gender"`
|
||||||
Medal string `json:"Medal"`
|
// Medal string `json:"Medal"`
|
||||||
Season string `json:"Season"`
|
// Season string `json:"Season"`
|
||||||
Sport string `json:"Sport"`
|
// Sport string `json:"Sport"`
|
||||||
Year int `json:"Year"`
|
// Year int `json:"Year"`
|
||||||
} `json:"_source"`
|
//} `json:"_source"`
|
||||||
} `json:"hits"`
|
} `json:"hits"`
|
||||||
} `json:"hits"`
|
} `json:"hits"`
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,8 @@ func ZincSearch(query map[string]interface{}) (rest Response, err error) {
|
|||||||
log.Println("解析响应失败", err)
|
log.Println("解析响应失败", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
return rest, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZincPut(data map[string]interface{}) (err error) {
|
func ZincPut(data map[string]interface{}) (err error) {
|
||||||
|
Reference in New Issue
Block a user