Merge remote-tracking branch 'origin/feat/1.0.2/user' into test

This commit is contained in:
LinkinStar 2022-12-28 18:08:52 +08:00
commit e1e9d65be1
3 changed files with 19 additions and 16 deletions

View File

@ -466,6 +466,7 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)
Where(builder.Eq{"tag_rel.object_id": r["question_id"]}).
And(builder.Eq{"tag_rel.status": entity.TagRelStatusAvailable}).
UseBool("recommend", "reserved").
OrderBy("tag.recommend DESC, tag.reserved DESC, tag.id DESC").
Find(&tagsEntity)
if err != nil {

View File

@ -26,6 +26,7 @@ type SearchObject struct {
}
type TagResp struct {
ID string `json:"-"`
SlugName string `json:"slug_name"`
DisplayName string `json:"display_name"`
// if main tag slug name is not empty, this tag is synonymous with the main tag

View File

@ -330,28 +330,31 @@ func (ts *TagCommonService) tagFormatRecommendAndReserved(ctx context.Context, t
// BatchGetObjectTag batch get object tag
func (ts *TagCommonService) BatchGetObjectTag(ctx context.Context, objectIds []string) (map[string][]*schema.TagResp, error) {
objectIDTagMap := make(map[string][]*schema.TagResp)
tagIDList := make([]string, 0)
tagsInfoMap := make(map[string]*entity.Tag)
tagList, err := ts.tagRelRepo.BatchGetObjectTagRelList(ctx, objectIds)
objectTagRelList, err := ts.tagRelRepo.BatchGetObjectTagRelList(ctx, objectIds)
if err != nil {
return objectIDTagMap, err
}
for _, tag := range tagList {
tagIDList := make([]string, 0)
for _, tag := range objectTagRelList {
tagIDList = append(tagIDList, tag.TagID)
}
tagsInfoList, err := ts.GetTagListByIDs(ctx, tagIDList)
if err != nil {
return objectIDTagMap, err
}
for _, item := range tagsInfoList {
tagsInfoMap[item.ID] = item
tagsInfoMapping := make(map[string]*entity.Tag)
tagsRank := make(map[string]int) // Used for sorting
for idx, item := range tagsInfoList {
tagsInfoMapping[item.ID] = item
tagsRank[item.ID] = idx
}
for _, item := range tagList {
_, ok := tagsInfoMap[item.TagID]
for _, item := range objectTagRelList {
_, ok := tagsInfoMapping[item.TagID]
if ok {
tagInfo := tagsInfoMap[item.TagID]
tagInfo := tagsInfoMapping[item.TagID]
t := &schema.TagResp{
ID: tagInfo.ID,
SlugName: tagInfo.SlugName,
DisplayName: tagInfo.DisplayName,
MainTagSlugName: tagInfo.MainTagSlugName,
@ -361,12 +364,10 @@ func (ts *TagCommonService) BatchGetObjectTag(ctx context.Context, objectIds []s
objectIDTagMap[item.ObjectID] = append(objectIDTagMap[item.ObjectID], t)
}
}
for _, taglist := range objectIDTagMap {
sort.SliceStable(taglist, func(i, j int) bool {
return taglist[i].Reserved
})
sort.SliceStable(taglist, func(i, j int) bool {
return taglist[i].Recommend
// The sorting in tagsRank is correct, object tags should be sorted by tagsRank
for _, objectTags := range objectIDTagMap {
sort.SliceStable(objectTags, func(i, j int) bool {
return tagsRank[objectTags[i].ID] < tagsRank[objectTags[j].ID]
})
}
return objectIDTagMap, nil