Bläddra i källkod

update findShortVideo

reghao 1 år sedan
förälder
incheckning
98e8c59232

+ 7 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/VideoRepository.java

@@ -8,6 +8,7 @@ import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.po.VideoStatistic;
 import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
 import cn.reghao.oss.sdk.model.dto.media.VideoUrlDto;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -96,6 +97,12 @@ public class VideoRepository {
         return videoPostMapper.findGroupByPublishBy();
     }
 
+    @Cacheable(cacheNames = "tnb:content:short_video", unless = "#result == null")
+    public List<String> getShortVideoIds(List<Integer> userScopes) {
+        List<String> videoIds = videoPostMapper.findShortVideo(userScopes);
+        return videoIds;
+    }
+
     public VideoPost getVideoPost(String videoId) {
         return videoPostMapper.findByVideoId(videoId);
     }

+ 5 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostQueryImpl.java

@@ -16,6 +16,7 @@ import cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryPostMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoStatisticMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoTagMapper;
+import cn.reghao.tnb.content.app.vod.db.repository.VideoRepository;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategoryPost;
@@ -57,17 +58,19 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private final VideoTagMapper videoTagMapper;
     private final ContentPermission contentPermission;
     private final CategoryService categoryService;
+    private final VideoRepository videoRepository;
     private final Random random = new SecureRandom();
 
     public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
                               VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
-                              ContentPermission contentPermission, CategoryService categoryService) {
+                              ContentPermission contentPermission, CategoryService categoryService, VideoRepository videoRepository) {
         this.videoPostMapper = videoPostMapper;
         this.videoTagMapper = videoTagMapper;
         this.videoStatisticMapper = videoStatisticMapper;
         this.videoCategoryPostMapper = videoCategoryPostMapper;
         this.contentPermission = contentPermission;
         this.categoryService = categoryService;
+        this.videoRepository = videoRepository;
     }
 
     public List<VideoCard> getVideoCards(List<String> videoIds) {
@@ -122,7 +125,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private String getRandomVideoId() {
         long loginUser = UserContext.getUser();
         List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
-        List<String> videoIds = videoPostMapper.findShortVideo(userScopes);
+        List<String> videoIds = videoRepository.getShortVideoIds(userScopes);
         if (videoIds.isEmpty()) {
             return null;
         }