4
0
Эх сурвалжийг харах

Do not try to update a duplicated feed after a refresh

Frédéric Guillot 5 жил өмнө
parent
commit
0d0395b4e3

+ 7 - 0
reader/feed/handler.go

@@ -127,6 +127,13 @@ func (h *Handler) RefreshFeed(userID, feedID int64) error {
 		return requestErr
 		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) {
 	if originalFeed.IgnoreHTTPCache || response.IsModified(originalFeed.EtagHeader, originalFeed.LastModifiedHeader) {
 		logger.Debug("[Handler:RefreshFeed] Feed #%d has been modified", feedID)
 		logger.Debug("[Handler:RefreshFeed] Feed #%d has been modified", feedID)
 
 

+ 8 - 0
storage/feed.go

@@ -68,6 +68,14 @@ func (s *Storage) FeedURLExists(userID int64, feedURL string) bool {
 	return result
 	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.
 // CountFeeds returns the number of feeds that belongs to the given user.
 func (s *Storage) CountFeeds(userID int64) int {
 func (s *Storage) CountFeeds(userID int64) int {
 	var result int
 	var result int