From 0d0395b4e3413cee607ac7017698c141a3f0383d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 20 Sep 2020 23:29:51 -0700 Subject: [PATCH] Do not try to update a duplicated feed after a refresh --- reader/feed/handler.go | 7 +++++++ storage/feed.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/reader/feed/handler.go b/reader/feed/handler.go index 6c039ff6..e1bedaab 100644 --- a/reader/feed/handler.go +++ b/reader/feed/handler.go @@ -127,6 +127,13 @@ func (h *Handler) RefreshFeed(userID, feedID int64) error { return requestErr } + if h.store.AnotherFeedURLExists(userID, originalFeed.ID, response.EffectiveURL) { + storeErr := errors.NewLocalizedError(errDuplicate, response.EffectiveURL) + originalFeed.WithError(storeErr.Error()) + h.store.UpdateFeedError(originalFeed) + return storeErr + } + if originalFeed.IgnoreHTTPCache || response.IsModified(originalFeed.EtagHeader, originalFeed.LastModifiedHeader) { logger.Debug("[Handler:RefreshFeed] Feed #%d has been modified", feedID) diff --git a/storage/feed.go b/storage/feed.go index 508288ac..55ce6e83 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -68,6 +68,14 @@ func (s *Storage) FeedURLExists(userID int64, feedURL string) bool { return result } +// AnotherFeedURLExists checks if the user a duplicated feed. +func (s *Storage) AnotherFeedURLExists(userID, feedID int64, feedURL string) bool { + var result bool + query := `SELECT true FROM feeds WHERE id <> $1 AND user_id=$2 AND feed_url=$3` + s.db.QueryRow(query, feedID, userID, feedURL).Scan(&result) + return result +} + // CountFeeds returns the number of feeds that belongs to the given user. func (s *Storage) CountFeeds(userID int64) int { var result int