From 42ea24f2f41ce04588aa929e5ffdaf1dbeb1a700 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Wed, 9 Dec 2020 22:13:09 +0100 Subject: Remove LastModified-based cursor when updating feeds We remove the call to readSince() as some feeds push new articles with pubDate prior to the lastModified time stored for these feeds (e.g. lemonde.fr). As we go through all items of a feed again and again, we prevent the constant update of an item's lastModified timestamp by keeping the previous one if its fingerprint does not change. Fixes #921 Signed-off-by: Kevin Decherf --- tests/Unit/Fetcher/FeedFetcherTest.php | 43 ++++++---------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php index 58504f3f1..6a1153b83 100644 --- a/tests/Unit/Fetcher/FeedFetcherTest.php +++ b/tests/Unit/Fetcher/FeedFetcherTest.php @@ -222,28 +222,12 @@ class FeedFetcherTest extends TestCase $this->assertTrue($this->fetcher->canHandle($url)); } - /** - * Test if empty is logged when the feed remain the same. - */ - public function testNoFetchIfNotModified() - { - $this->setUpReader($this->url, '@0', false); - $this->logger->expects($this->once()) - ->method('debug') - ->with( - 'Feed {url} was not modified since last fetch. old: {old}, new: {new}' - ); - $result = $this->fetcher->fetch($this->url, false, '@0', false, null, null); - - $this->assertSame([null, []], $result); - } - /** * Test if empty is logged when the feed remain the same. */ public function testFetchIfNoModifiedExists() { - $this->setUpReader($this->url, null, true); + $this->setUpReader($this->url, true); $item = $this->createItem(); $feed = $this->createFeed(); $this->mockIterator($this->feed_mock, [$this->item_mock]); @@ -294,7 +278,7 @@ class FeedFetcherTest extends TestCase $this->body = $body; $this->parsed_body = $parsed_body; - $this->setUpReader($this->url, null, true); + $this->setUpReader($this->url, true); $item = $this->createItem(); $feed = $this->createFeed(); $this->mockIterator($this->feed_mock, [$this->item_mock]); @@ -552,26 +536,13 @@ class FeedFetcherTest extends TestCase * @param string|null $modifiedDate Date of last fetch * @param bool $modified If the feed will be modified */ - private function setUpReader(string $url = '', ?string $modifiedDate = '@1553118393', bool $modified = true) + private function setUpReader(string $url = '', bool $modified = true) { - if (is_null($modifiedDate)) { - $this->reader->expects($this->once()) - ->method('read') - ->with($url) - ->will($this->returnValue($this->result)); - } else { - $this->reader->expects($this->once()) - ->method('readSince') - ->with($url, new DateTime($modifiedDate)) - ->will($this->returnValue($this->result)); - } + $this->reader->expects($this->once()) + ->method('read') + ->with($url) + ->will($this->returnValue($this->result)); - $this->result->expects($this->once()) - ->method('getResponse') - ->will($this->returnValue($this->response)); - $this->response->expects($this->once()) - ->method('isModified') - ->will($this->returnValue($modified !== false)); $this->location = $url; if (!$modified) { -- cgit v1.2.3