modified internal/db/article.go +0 -21
| @@ -355,27 +355,6 @@ func (db *DB) GetArticleByURL(ctx context.Context, url string) (*Article, error) |
| 355 | 355 | return a, nil |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | | -func (db *DB) GetReadCount(ctx context.Context, userDID, feedURL string) (int, error) { |
| 359 | | - var count int |
| 360 | | - if feedURL != "" { |
| 361 | | - err := db.QueryRowContext(ctx, ` |
| 362 | | - SELECT COUNT(*) |
| 363 | | - FROM articles a |
| 364 | | - JOIN read_state r ON r.user_did = ? AND r.article_id = a.id |
| 365 | | - WHERE a.feed_url = ? AND r.is_read = 1 |
| 366 | | - `, userDID, feedURL).Scan(&count) |
| 367 | | - return count, err |
| 368 | | - } |
| 369 | | - err := db.QueryRowContext(ctx, ` |
| 370 | | - SELECT COUNT(*) |
| 371 | | - FROM articles a |
| 372 | | - JOIN subscriptions s ON a.feed_url = s.feed_url AND s.user_did = ? |
| 373 | | - JOIN read_state r ON r.user_did = ? AND r.article_id = a.id |
| 374 | | - WHERE r.is_read = 1 |
| 375 | | - `, userDID, userDID).Scan(&count) |
| 376 | | - return count, err |
| 377 | | -} |
| 378 | | - |
| 379 | 358 | func (db *DB) CountNewArticles(ctx context.Context, userDID string, since time.Time) (int, error) { |
| 380 | 359 | var count int |
| 381 | 360 | err := db.QueryRowContext(ctx, ` |
| @@ -355,27 +355,6 @@ func (db *DB) GetArticleByURL(ctx context.Context, url string) (*Article, error) |
| 355 | return a, nil | 355 | return a, nil |
| 356 | } | 356 | } |
| 357 | | 357 | |
| 358 | -func (db *DB) GetReadCount(ctx context.Context, userDID, feedURL string) (int, error) { | | |
| 359 | - var count int | | |
| 360 | - if feedURL != "" { | | |
| 361 | - err := db.QueryRowContext(ctx, ` | | |
| 362 | - SELECT COUNT(*) | | |
| 363 | - FROM articles a | | |
| 364 | - JOIN read_state r ON r.user_did = ? AND r.article_id = a.id | | |
| 365 | - WHERE a.feed_url = ? AND r.is_read = 1 | | |
| 366 | - `, userDID, feedURL).Scan(&count) | | |
| 367 | - return count, err | | |
| 368 | - } | | |
| 369 | - err := db.QueryRowContext(ctx, ` | | |
| 370 | - SELECT COUNT(*) | | |
| 371 | - FROM articles a | | |
| 372 | - JOIN subscriptions s ON a.feed_url = s.feed_url AND s.user_did = ? | | |
| 373 | - JOIN read_state r ON r.user_did = ? AND r.article_id = a.id | | |
| 374 | - WHERE r.is_read = 1 | | |
| 375 | - `, userDID, userDID).Scan(&count) | | |
| 376 | - return count, err | | |
| 377 | -} | | |
| 378 | - | | |
| 379 | func (db *DB) CountNewArticles(ctx context.Context, userDID string, since time.Time) (int, error) { | 358 | func (db *DB) CountNewArticles(ctx context.Context, userDID string, since time.Time) (int, error) { |
| 380 | var count int | 359 | var count int |
| 381 | err := db.QueryRowContext(ctx, ` | 360 | err := db.QueryRowContext(ctx, ` |
modified internal/server/articles_handler.go +2 -2
| @@ -39,8 +39,8 @@ func (s *Server) handleArticles(w http.ResponseWriter, r *http.Request) { |
| 39 | 39 | page := pageFromRequest(r, 50) |
| 40 | 40 | |
| 41 | 41 | if status == "" && searchQuery == "" { |
| 42 | | - readCount, _ := s.db.GetReadCount(r.Context(), user.DID, feedURL) |
| 43 | | - if readCount > 0 { |
| 42 | + unreadCount, _ := s.db.GetUnreadCount(r.Context(), user.DID, feedURL) |
| 43 | + if unreadCount > 0 { |
| 44 | 44 | status = "unread" |
| 45 | 45 | } |
| 46 | 46 | } |
| @@ -39,8 +39,8 @@ func (s *Server) handleArticles(w http.ResponseWriter, r *http.Request) { |
| 39 | page := pageFromRequest(r, 50) | 39 | page := pageFromRequest(r, 50) |
| 40 | | 40 | |
| 41 | if status == "" && searchQuery == "" { | 41 | if status == "" && searchQuery == "" { |
| 42 | - readCount, _ := s.db.GetReadCount(r.Context(), user.DID, feedURL) | 42 | + unreadCount, _ := s.db.GetUnreadCount(r.Context(), user.DID, feedURL) |
| 43 | - if readCount > 0 { | 43 | + if unreadCount > 0 { |
| 44 | status = "unread" | 44 | status = "unread" |
| 45 | } | 45 | } |
| 46 | } | 46 | } |