Cumfiesta.24.06.16.ryan.reid.the.rise.of.the.cu...

const trendingContent = await prisma.trendingContent.findMany( where: whereClause, orderBy: trendScore: 'desc' , take: parseInt(limit), skip: parseInt(offset), include: _count: select: userBookmarks: true

To keep the feed fresh, you need automated scrapers or API integrations :

Simplified implementation:

# backend/services/trending_algorithm.py from datetime import datetime, timezone import math def calculate_trend_score(content, current_time): hours_since_publish = (current_time - content.published_at).total_seconds() / 3600 hours_since_decay_start = (current_time - content.decay_started_at).total_seconds() / 3600 CumFiesta.24.06.16.Ryan.Reid.The.Rise.Of.The.Cu...

useEffect(() => fetchTrending(); , [page]);

# Gravity factor (newer content gets boost) gravity = 1.5 if hours_since_publish < 24 else 1.8

await prisma.$transaction([ prisma.trendingContent.update( where: id: contentId , data: [type === 'like' ? 'likes' : type === 'share' ? 'shares' : 'views']: increment: 1 ), prisma.userInteraction.create( data: userId: req.user.id, contentId, type ) ]); const trendingContent = await prisma

const handleLike = async (itemId: string) => // Optimistic update setItems(items.map(item => item.id === itemId ? ...item, likes: item.likes + (item.userLiked ? -1 : 1), userLiked: !item.userLiked : item )); await fetch( /api/trending/$itemId/interact , method: 'POST', body: JSON.stringify( type: 'like' ), headers: 'Content-Type': 'application/json' ); ;

export default function TrendingFeed() const [items, setItems] = useState<TrendingItem[]>([]); const [loading, setLoading] = useState(false); const [page, setPage] = useState(0); const observerTarget = useRef(null);

const fetchTrending = async () => setLoading(true); const res = await fetch( /api/trending/feed?limit=15&offset=$page * 15 ); const newItems = await res.json(); setItems(prev => [...prev, ...newItems.data]); setLoading(false); ; userLiked: !item.userLiked : item ))

res.json( success: true ); ); // components/TrendingFeed.tsx import useState, useEffect, useRef from 'react'; import motion from 'framer-motion'; import HeartIcon, ShareIcon, ChatBubbleLeftIcon from '@heroicons/react/24/outline'; import HeartIcon as HeartSolidIcon from '@heroicons/react/24/solid'; interface TrendingItem id: string; title: string; thumbnailUrl: string; sourceUrl: string; likes: number; shares: number; trendScore: number; userLiked: boolean; contentType: 'VIDEO'

# Apply recency bonus if hours_since_publish < 2: score *= 1.5 return round(score, 6) // GET /api/trending/feed router.get('/feed', async (req, res) => { const limit = 20, offset = 0, contentType, category = req.query; const whereClause = {}; if (contentType) whereClause.contentType = contentType; if (category) whereClause.category = category;

score = math.log10(max(interactions, 1)) / ((hours_since_publish + 2) ** gravity)

# scraper/entertainment_aggregator.py import feedparser from selenium import webdriver def fetch_reddit_trending(): # r/all trending in entertainment reddit_url = "https://www.reddit.com/r/entertainment/top.json?t=day&limit=25" # Use praw library or requests with auth return posts