feat:为ListByFollowing方法添加上redis缓存

This commit is contained in:
Leon
2025-12-24 13:04:38 +08:00
parent f0411b4577
commit 94140c3c13
4 changed files with 41 additions and 7 deletions

View File

@@ -49,7 +49,7 @@ func (repo *FeedRepository) ListLikesCountWithCursor(ctx context.Context, limit
return videos, nil
}
func (repo *FeedRepository) ListByFollowing(ctx context.Context, limit int, viewerAccountID uint) ([]*video.Video, error) {
func (repo *FeedRepository) ListByFollowing(ctx context.Context, limit int, viewerAccountID uint, latestBefore time.Time) ([]*video.Video, error) {
var videos []*video.Video
query := repo.db.WithContext(ctx).Model(&video.Video{}).
Order("create_time DESC")
@@ -60,6 +60,9 @@ func (repo *FeedRepository) ListByFollowing(ctx context.Context, limit int, view
Where("follower_id = ?", viewerAccountID)
query = query.Where("author_id IN (?)", followingSubQuery)
}
if !latestBefore.IsZero() {
query = query.Where("create_time < ?", latestBefore)
}
if err := query.Limit(limit).Find(&videos).Error; err != nil {
return nil, err
}