Skip to content

Commit

Permalink
add GetIsFavoriteMap
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwin committed Feb 21, 2023
1 parent 0e6f11e commit 76893f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 13 additions & 2 deletions kitex_server/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package kitex_server

import (
"context"
"sync"

"github.com/ClubWeGo/douyin/pack"
"github.com/ClubWeGo/usermicro/kitex_gen/usermicro"
"github.com/ClubWeGo/videomicro/kitex_gen/videomicro"
"sync"


"github.com/ClubWeGo/douyin/biz/model/interaction"
"github.com/ClubWeGo/douyin/tools/errno"
Expand Down Expand Up @@ -160,6 +160,17 @@ func GetVideosFavoriteCountMap(idSet []int64, respVideosFavoriteCountMap chan ma
func GetIsFavoriteMap() (idSet []int64, currentUser int64, respIsFavoriteMap chan map[int64]bool, wg *sync.WaitGroup, errChan chan error) {
defer wg.Done()

res, err := FavoriteClient.FavoriteRelationsMethod(context.Background(), &favorite.FavoriteRelationsReq{
UserId: currentUser,
VideoIdList: idSet,
})
if err != nil {
respIsFavoriteMap <- map[int64]bool{}
errChan <- err
return
}
respIsFavoriteMap <- res.IsFavorites
errChan <- nil
// res, err := FavoriteClient.FavoriteRelationMethod(context.Background(), &favorite.FavoriteRelationReq{})
return
}
19 changes: 16 additions & 3 deletions kitex_server/videoservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ func GetVideoLatestMap(idSet []int64, currentUser int64, respVideoMap chan map[i
// 批量查询视频的评论数,传入视频id的切片,返回对应的评论数(需携带对应视频id),从comment服务

// 批量查询 is_favorite, 传入目标视频id切片和currentUser查is_favorite的切片(结果需要携带视频id,douyin里后续需要转成map):从favorite;
GetIsFavoriteMap()
respIsFavoriteMap := make(chan map[int64]int64, 1)
defer close(respIsFavoriteMap)
respIsFavoriteMapError := make(chan error, 1)
defer close(respIsFavoriteMapError)
wgVideo.Add(1)
go GetIsFavoriteMap(idSet, currentUser, respIsFavoriteMap, wgVideo, respIsFavoriteMapError)

// 等待数据
wgVideo.Wait()
Expand Down Expand Up @@ -104,6 +109,10 @@ func GetFeed(latestTime int64, currentUserId int64, limit int32) (resultList []*
for index, video := range r.VideoList {
authorIdSet[index] = video.AuthorId
}
videoIdSet := make([]int64, len(r.VideoList))
for index, video := range r.VideoList {
videoIdSet[index] = video.Id
}

wg := &sync.WaitGroup{}

Expand All @@ -123,7 +132,7 @@ func GetFeed(latestTime int64, currentUserId int64, limit int32) (resultList []*
respLatestVideoMapError := make(chan []error, 1)
defer close(respLatestVideoMapError)
wg.Add(1)
go GetVideoLatestMap(authorIdSet, currentUserId, respLatestVideoMap, wg, respLatestVideoMapError)
go GetVideoLatestMap(videoIdSet, currentUserId, respLatestVideoMap, wg, respLatestVideoMapError)

// 等待数据
wg.Wait()
Expand Down Expand Up @@ -181,6 +190,10 @@ func GetVideosByAuthorId(id int64) (resultList []*core.Video, err error) {

if r.Status {
authorIdSet := []int64{id} // 只有作者本人
videoIdSet := make([]int64, len(r.VideoList))
for index, video := range r.VideoList {
videoIdSet[index] = video.Id
}

wg := &sync.WaitGroup{}

Expand All @@ -198,7 +211,7 @@ func GetVideosByAuthorId(id int64) (resultList []*core.Video, err error) {
respLatestVideoMapError := make(chan []error, 1)
defer close(respLatestVideoMapError)
wg.Add(1)
go GetVideoLatestMap(authorIdSet, id, respLatestVideoMap, wg, respLatestVideoMapError)
go GetVideoLatestMap(videoIdSet, id, respLatestVideoMap, wg, respLatestVideoMapError)

// 等待数据
wg.Wait()
Expand Down

0 comments on commit 76893f3

Please sign in to comment.