Skip to content

Commit 2b8d736

Browse files
committed
Don't update last_fetched when given an older timestamp
1 parent 66398fd commit 2b8d736

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

app/repositories/feed_repository.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ def self.fetch_by_ids(ids)
88
end
99

1010
def self.update_last_fetched(feed, timestamp)
11-
is_invalid_timestamp = timestamp.nil? || timestamp.year < MIN_YEAR
12-
13-
feed.last_fetched = timestamp unless is_invalid_timestamp
14-
feed.save
11+
is_invalid_timestamp = timestamp.nil? ||
12+
timestamp.year < MIN_YEAR ||
13+
(feed.last_fetched && timestamp <= feed.last_fetched)
14+
15+
unless is_invalid_timestamp
16+
feed.last_fetched = timestamp
17+
feed.save
18+
end
1519
end
1620

1721
def self.delete(feed_id)

spec/repositories/feed_repository_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,14 @@
3232

3333
feed.last_fetched.should eq timestamp
3434
end
35+
36+
it "doesn't update if timestamp is older than the current value" do
37+
feed = Feed.new(last_fetched: timestamp)
38+
one_week_ago = timestamp - 1.week
39+
40+
result = FeedRepository.update_last_fetched(feed, one_week_ago)
41+
42+
feed.last_fetched.should eq timestamp
43+
end
3544
end
3645
end

0 commit comments

Comments
 (0)