💄 Optimized the feed

This commit is contained in:
2025-04-06 14:15:54 +08:00
parent e34f248cfa
commit 6cfa6e8285
2 changed files with 15 additions and 5 deletions

View File

@ -3,13 +3,18 @@ package services
import (
"git.solsynth.dev/hypernet/reader/pkg/internal/database"
"git.solsynth.dev/hypernet/reader/pkg/internal/models"
"time"
)
func GetTodayFeedRandomly(limit int) ([]models.SubscriptionItem, error) {
func GetTodayFeedRandomly(limit int, cursor *time.Time) ([]models.SubscriptionItem, error) {
tx := database.C
if cursor != nil {
tx = tx.Where("published_at < ?", *cursor)
}
var articles []models.SubscriptionItem
if err := database.C.Limit(limit).
Where("DATE(created_at) = CURRENT_DATE"). // Created in today
Order("RANDOM()").
if err := tx.Limit(limit).
Order("published_at DESC").
Omit("Content").
Preload("Feed").
Find(&articles).Error; err != nil {