aboutsummaryrefslogtreecommitdiffhomepage
path: root/storage
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-10-07 12:50:59 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-10-07 12:50:59 -0700
commitddfe969d6cbc8d23326cb9a3ca9a265d4e9d3e45 (patch)
tree16a6d739c06375c6531673f65f4b0a401bb047e1 /storage
parent98206059fc55e68b3b0f8c95b74c331dd56da84c (diff)
Improve Fever API performances when marking a feed or group as read
Diffstat (limited to 'storage')
-rw-r--r--storage/entry.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/storage/entry.go b/storage/entry.go
index 9fd8a53..ff081d4 100644
--- a/storage/entry.go
+++ b/storage/entry.go
@@ -256,7 +256,7 @@ func (s *Storage) FlushHistory(userID int64) error {
return nil
}
-// MarkAllAsRead set all entries with the status "unread" to "read".
+// MarkAllAsRead updates all user entries to the read status.
func (s *Storage) MarkAllAsRead(userID int64) error {
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkAllAsRead] userID=%d", userID))
@@ -269,6 +269,49 @@ func (s *Storage) MarkAllAsRead(userID int64) error {
return nil
}
+// MarkFeedAsRead updates all feed entries to the read status.
+func (s *Storage) MarkFeedAsRead(userID, feedID int64, before time.Time) error {
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkFeedAsRead] userID=%d, feedID=%d, before=%v", userID, feedID, before))
+
+ query := `
+ UPDATE entries
+ SET status=$1
+ WHERE user_id=$2 AND feed_id=$3 AND status=$4 AND published_at < $5
+ `
+
+ result, err := s.db.Exec(query, model.EntryStatusRead, userID, feedID, model.EntryStatusUnread, before)
+ if err != nil {
+ return fmt.Errorf("unable to mark feed entries as read: %v", err)
+ }
+
+ count, _ := result.RowsAffected()
+ logger.Debug("[Storage:MarkFeedAsRead] %d items marked as read", count)
+
+ return nil
+}
+
+// MarkCategoryAsRead updates all category entries to the read status.
+func (s *Storage) MarkCategoryAsRead(userID, categoryID int64, before time.Time) error {
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkCategoryAsRead] userID=%d, categoryID=%d, before=%v", userID, categoryID, before))
+
+ query := `
+ UPDATE entries
+ SET status=$1
+ WHERE
+ user_id=$2 AND status=$3 AND published_at < $4 AND feed_id IN (SELECT id FROM feeds WHERE user_id=$2 AND category_id=$5)
+ `
+
+ result, err := s.db.Exec(query, model.EntryStatusRead, userID, model.EntryStatusUnread, before, categoryID)
+ if err != nil {
+ return fmt.Errorf("unable to mark category entries as read: %v", err)
+ }
+
+ count, _ := result.RowsAffected()
+ logger.Debug("[Storage:MarkCategoryAsRead] %d items marked as read", count)
+
+ return nil
+}
+
// EntryURLExists returns true if an entry with this URL already exists.
func (s *Storage) EntryURLExists(userID int64, entryURL string) bool {
var result int