mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
perf(storage): avoid heavy-weight SQL when marking feed as read
There is no need to perform a heavy-weight SQL query gathering all the information available on a feed when we're only interested in its last check timestamp.
This commit is contained in:
parent
826977bc8c
commit
924293ee5c
2 changed files with 14 additions and 8 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"miniflux.app/v2/internal/config"
|
"miniflux.app/v2/internal/config"
|
||||||
"miniflux.app/v2/internal/model"
|
"miniflux.app/v2/internal/model"
|
||||||
|
@ -40,6 +41,17 @@ func (s *Storage) FeedExists(userID, feedID int64) bool {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckedAt returns when the feed was last checked.
|
||||||
|
func (s *Storage) CheckedAt(userID, feedID int64) (time.Time, error) {
|
||||||
|
var result time.Time
|
||||||
|
query := `SELECT checked_at FROM feeds WHERE user_id=$1 AND id=$2 LIMIT 1`
|
||||||
|
err := s.db.QueryRow(query, userID, feedID).Scan(&result)
|
||||||
|
if err != nil {
|
||||||
|
return time.Now(), err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CategoryFeedExists returns true if the given feed exists that belongs to the given category.
|
// CategoryFeedExists returns true if the given feed exists that belongs to the given category.
|
||||||
func (s *Storage) CategoryFeedExists(userID, categoryID, feedID int64) bool {
|
func (s *Storage) CategoryFeedExists(userID, categoryID, feedID int64) bool {
|
||||||
var result bool
|
var result bool
|
||||||
|
|
|
@ -15,19 +15,13 @@ func (h *handler) markFeedAsRead(w http.ResponseWriter, r *http.Request) {
|
||||||
feedID := request.RouteInt64Param(r, "feedID")
|
feedID := request.RouteInt64Param(r, "feedID")
|
||||||
userID := request.UserID(r)
|
userID := request.UserID(r)
|
||||||
|
|
||||||
feed, err := h.store.FeedByID(userID, feedID)
|
checkedAt, err := h.store.CheckedAt(userID, feedID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
html.ServerError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if feed == nil {
|
|
||||||
html.NotFound(w, r)
|
html.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.store.MarkFeedAsRead(userID, feedID, feed.CheckedAt); err != nil {
|
if err = h.store.MarkFeedAsRead(userID, feedID, checkedAt); err != nil {
|
||||||
html.ServerError(w, r, err)
|
html.ServerError(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue