Sort articles from the future lastUnverified
8844048 parent: 9a6ff22 modified
internal/cluster/scoring.go +2 -1 | @@ -224,7 +224,8 @@ func (e *Engine) ComputeArticleRecommendationsOnDemand(ctx context.Context, user | ||
| 224 | 224 | JOIN articles a ON a.feed_url = la.feed_url AND a.url = la.article_url |
| 225 | 225 | LEFT JOIN feeds f ON f.feed_url = la.feed_url |
| 226 | 226 | LEFT JOIN social_likes sl ON sl.feed_url = la.feed_url AND sl.article_url = la.article_url |
| 227 | - ORDER BY score DESC, a.published DESC | |
| 227 | + -- Future-published articles (e.g., scheduled) sort last | |
| 228 | + ORDER BY score DESC, (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC | |
| 228 | 229 | LIMIT ? |
| 229 | 230 | `, userDID, userDID, userDID, userDID, userDID, userDID, w.WLike, w.WSocial, limit) |
| 230 | 231 | if err != nil { |
| @@ -224,7 +224,8 @@ func (e *Engine) ComputeArticleRecommendationsOnDemand(ctx context.Context, user | |||
| 224 | JOIN articles a ON a.feed_url = la.feed_url AND a.url = la.article_url | 224 | JOIN articles a ON a.feed_url = la.feed_url AND a.url = la.article_url |
| 225 | LEFT JOIN feeds f ON f.feed_url = la.feed_url | 225 | LEFT JOIN feeds f ON f.feed_url = la.feed_url |
| 226 | LEFT JOIN social_likes sl ON sl.feed_url = la.feed_url AND sl.article_url = la.article_url | 226 | LEFT JOIN social_likes sl ON sl.feed_url = la.feed_url AND sl.article_url = la.article_url |
| 227 | - ORDER BY score DESC, a.published DESC | 227 | + -- Future-published articles (e.g., scheduled) sort last |
| 228 | + ORDER BY score DESC, (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC | ||
| 228 | LIMIT ? | 229 | LIMIT ? |
| 229 | `, userDID, userDID, userDID, userDID, userDID, userDID, w.WLike, w.WSocial, limit) | 230 | `, userDID, userDID, userDID, userDID, userDID, userDID, w.WLike, w.WSocial, limit) |
| 230 | if err != nil { | 231 | if err != nil { |
modified
internal/db/article.go +6 -3 | @@ -158,7 +158,8 @@ func (db *DB) ListArticles(ctx context.Context, userDID, feedURL string, limit, | ||
| 158 | 158 | args = []any{userDID, userDID, userDID} |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | |
| 161 | + // Future-published articles (e.g., scheduled) sort last | |
| 162 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | |
| 162 | 163 | args = append(args, limit, offset) |
| 163 | 164 | |
| 164 | 165 | rows, err := db.QueryContext(ctx, query, args...) |
| @@ -221,7 +222,8 @@ func (db *DB) ListUnreadArticles(ctx context.Context, userDID, feedURL string, l | ||
| 221 | 222 | args = []any{userDID, userDID, userDID} |
| 222 | 223 | } |
| 223 | 224 | |
| 224 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | |
| 225 | + // Future-published articles (e.g., scheduled) sort last | |
| 226 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | |
| 225 | 227 | args = append(args, limit, offset) |
| 226 | 228 | |
| 227 | 229 | rows, err := db.QueryContext(ctx, query, args...) |
| @@ -284,7 +286,8 @@ func (db *DB) ListReadArticles(ctx context.Context, userDID, feedURL string, lim | ||
| 284 | 286 | args = []any{userDID, userDID, userDID} |
| 285 | 287 | } |
| 286 | 288 | |
| 287 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | |
| 289 | + // Future-published articles (e.g., scheduled) sort last | |
| 290 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | |
| 288 | 291 | args = append(args, limit, offset) |
| 289 | 292 | |
| 290 | 293 | rows, err := db.QueryContext(ctx, query, args...) |
| @@ -158,7 +158,8 @@ func (db *DB) ListArticles(ctx context.Context, userDID, feedURL string, limit, | |||
| 158 | args = []any{userDID, userDID, userDID} | 158 | args = []any{userDID, userDID, userDID} |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | 161 | + // Future-published articles (e.g., scheduled) sort last |
| 162 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | ||
| 162 | args = append(args, limit, offset) | 163 | args = append(args, limit, offset) |
| 163 | 164 | ||
| 164 | rows, err := db.QueryContext(ctx, query, args...) | 165 | rows, err := db.QueryContext(ctx, query, args...) |
| @@ -221,7 +222,8 @@ func (db *DB) ListUnreadArticles(ctx context.Context, userDID, feedURL string, l | |||
| 221 | args = []any{userDID, userDID, userDID} | 222 | args = []any{userDID, userDID, userDID} |
| 222 | } | 223 | } |
| 223 | 224 | ||
| 224 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | 225 | + // Future-published articles (e.g., scheduled) sort last |
| 226 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | ||
| 225 | args = append(args, limit, offset) | 227 | args = append(args, limit, offset) |
| 226 | 228 | ||
| 227 | rows, err := db.QueryContext(ctx, query, args...) | 229 | rows, err := db.QueryContext(ctx, query, args...) |
| @@ -284,7 +286,8 @@ func (db *DB) ListReadArticles(ctx context.Context, userDID, feedURL string, lim | |||
| 284 | args = []any{userDID, userDID, userDID} | 286 | args = []any{userDID, userDID, userDID} |
| 285 | } | 287 | } |
| 286 | 288 | ||
| 287 | - query += ` ORDER BY a.published DESC LIMIT ? OFFSET ?` | 289 | + // Future-published articles (e.g., scheduled) sort last |
| 290 | + query += ` ORDER BY (CASE WHEN a.published > 'now' THEN 1 ELSE 0 END), a.published DESC LIMIT ? OFFSET ?` | ||
| 288 | args = append(args, limit, offset) | 291 | args = append(args, limit, offset) |
| 289 | 292 | ||
| 290 | rows, err := db.QueryContext(ctx, query, args...) | 293 | rows, err := db.QueryContext(ctx, query, args...) |
modified
internal/db/social.go +4 -2 | @@ -255,7 +255,8 @@ func (db *DB) ListTrendingArticlesForUser(ctx context.Context, userDID, since st | ||
| 255 | 255 | UNION SELECT f.target_did FROM follows f WHERE f.user_did = ? |
| 256 | 256 | ) |
| 257 | 257 | GROUP BY ar.id |
| 258 | - ORDER BY like_count DESC, annotation_count DESC, ar.published DESC | |
| 258 | + -- Future-published articles (e.g., scheduled) sort last | |
| 259 | + ORDER BY like_count DESC, annotation_count DESC, (CASE WHEN ar.published > 'now' THEN 1 ELSE 0 END), ar.published DESC | |
| 259 | 260 | LIMIT ? OFFSET ? |
| 260 | 261 | `, since, userDID, since, userDID, userDID, userDID, userDID, userDID, limit, offset) |
| 261 | 262 | if err != nil { |
| @@ -291,7 +292,8 @@ func (db *DB) ListTrendingArticles(ctx context.Context, userDID, since string, l | ||
| 291 | 292 | LEFT JOIN likes ul ON ul.feed_url = l.feed_url AND ul.article_url = l.article_url AND ul.author_did = ? |
| 292 | 293 | WHERE l.created_at >= ? |
| 293 | 294 | GROUP BY ar.id |
| 294 | - ORDER BY like_count DESC, annotation_count DESC, ar.published DESC | |
| 295 | + -- Future-published articles (e.g., scheduled) sort last | |
| 296 | + ORDER BY like_count DESC, annotation_count DESC, (CASE WHEN ar.published > 'now' THEN 1 ELSE 0 END), ar.published DESC | |
| 295 | 297 | LIMIT ? OFFSET ? |
| 296 | 298 | `, since, userDID, since, limit, offset) |
| 297 | 299 | if err != nil { |
| @@ -255,7 +255,8 @@ func (db *DB) ListTrendingArticlesForUser(ctx context.Context, userDID, since st | |||
| 255 | UNION SELECT f.target_did FROM follows f WHERE f.user_did = ? | 255 | UNION SELECT f.target_did FROM follows f WHERE f.user_did = ? |
| 256 | ) | 256 | ) |
| 257 | GROUP BY ar.id | 257 | GROUP BY ar.id |
| 258 | - ORDER BY like_count DESC, annotation_count DESC, ar.published DESC | 258 | + -- Future-published articles (e.g., scheduled) sort last |
| 259 | + ORDER BY like_count DESC, annotation_count DESC, (CASE WHEN ar.published > 'now' THEN 1 ELSE 0 END), ar.published DESC | ||
| 259 | LIMIT ? OFFSET ? | 260 | LIMIT ? OFFSET ? |
| 260 | `, since, userDID, since, userDID, userDID, userDID, userDID, userDID, limit, offset) | 261 | `, since, userDID, since, userDID, userDID, userDID, userDID, userDID, limit, offset) |
| 261 | if err != nil { | 262 | if err != nil { |
| @@ -291,7 +292,8 @@ func (db *DB) ListTrendingArticles(ctx context.Context, userDID, since string, l | |||
| 291 | LEFT JOIN likes ul ON ul.feed_url = l.feed_url AND ul.article_url = l.article_url AND ul.author_did = ? | 292 | LEFT JOIN likes ul ON ul.feed_url = l.feed_url AND ul.article_url = l.article_url AND ul.author_did = ? |
| 292 | WHERE l.created_at >= ? | 293 | WHERE l.created_at >= ? |
| 293 | GROUP BY ar.id | 294 | GROUP BY ar.id |
| 294 | - ORDER BY like_count DESC, annotation_count DESC, ar.published DESC | 295 | + -- Future-published articles (e.g., scheduled) sort last |
| 296 | + ORDER BY like_count DESC, annotation_count DESC, (CASE WHEN ar.published > 'now' THEN 1 ELSE 0 END), ar.published DESC | ||
| 295 | LIMIT ? OFFSET ? | 297 | LIMIT ? OFFSET ? |
| 296 | `, since, userDID, since, limit, offset) | 298 | `, since, userDID, since, limit, offset) |
| 297 | if err != nil { | 299 | if err != nil { |