From b62c11a43eab6f103110346989ea44026802e4b2 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 7 Nov 2020 08:11:06 -0500 Subject: [PATCH] Lasts tests for icon cache; fixes #177 --- lib/Database.php | 2 +- tests/cases/Database/SeriesCleanup.php | 40 +++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 6844541..92ddb89 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1287,7 +1287,7 @@ class Database { // first unmark any icons which are no longer orphaned; an icon is considered orphaned if it is not used or only used by feeds which are themselves orphaned $this->db->query("UPDATE arsse_icons set orphaned = null where id in (select distinct icon from arsse_feeds where icon is not null and orphaned is null)"); // next mark any newly orphaned icons with the current date and time - $this->db->query("UPDATE arsse_icons set orphaned = CURRENT_TIMESTAMP where id not in (select distinct icon from arsse_feeds where icon is not null and orphaned is null)"); + $this->db->query("UPDATE arsse_icons set orphaned = CURRENT_TIMESTAMP where orphaned is null and id not in (select distinct icon from arsse_feeds where icon is not null and orphaned is null)"); // finally delete icons that have been orphaned longer than the feed retention period, if a a purge threshold has been specified $out = 0; if (Arsse::$conf->purgeFeeds) { diff --git a/tests/cases/Database/SeriesCleanup.php b/tests/cases/Database/SeriesCleanup.php index ad1d7f1..1a0e1c7 100644 --- a/tests/cases/Database/SeriesCleanup.php +++ b/tests/cases/Database/SeriesCleanup.php @@ -73,10 +73,9 @@ trait SeriesCleanup { 'orphaned' => "datetime", ], 'rows' => [ - [1,'http://localhost:8000/Icon/PNG',null], - [2,'http://localhost:8000/Icon/GIF',null], + [1,'http://localhost:8000/Icon/PNG',$daybefore], + [2,'http://localhost:8000/Icon/GIF',$daybefore], [3,'http://localhost:8000/Icon/SVG1',null], - [4,'http://localhost:8000/Icon/SVG2',null], ], ], 'arsse_feeds' => [ @@ -86,12 +85,13 @@ trait SeriesCleanup { 'title' => "str", 'orphaned' => "datetime", 'size' => "int", + 'icon' => "int", ], 'rows' => [ - [1,"http://example.com/1","",$daybefore,2], //latest two articles should be kept - [2,"http://example.com/2","",$yesterday,0], - [3,"http://example.com/3","",null,0], - [4,"http://example.com/4","",$nowish,0], + [1,"http://example.com/1","",$daybefore,2,null], //latest two articles should be kept + [2,"http://example.com/2","",$yesterday,0,2], + [3,"http://example.com/3","",null,0,1], + [4,"http://example.com/4","",$nowish,0,null], ], ], 'arsse_subscriptions' => [ @@ -193,6 +193,32 @@ trait SeriesCleanup { $this->compareExpectations(static::$drv, $state); } + public function testCleanUpOrphanedIcons(): void { + Arsse::$db->iconCleanup(); + $now = gmdate("Y-m-d H:i:s"); + $state = $this->primeExpectations($this->data, [ + 'arsse_icons' => ["id","orphaned"], + ]); + $state['arsse_icons']['rows'][0][1] = null; + unset($state['arsse_icons']['rows'][1]); + $state['arsse_icons']['rows'][2][1] = $now; + $this->compareExpectations(static::$drv, $state); + } + + public function testCleanUpOrphanedIconsWithUnlimitedRetention(): void { + Arsse::$conf->import([ + 'purgeFeeds' => null, + ]); + Arsse::$db->iconCleanup(); + $now = gmdate("Y-m-d H:i:s"); + $state = $this->primeExpectations($this->data, [ + 'arsse_icons' => ["id","orphaned"], + ]); + $state['arsse_icons']['rows'][0][1] = null; + $state['arsse_icons']['rows'][2][1] = $now; + $this->compareExpectations(static::$drv, $state); + } + public function testCleanUpOldArticlesWithStandardRetention(): void { Arsse::$db->articleCleanup(); $state = $this->primeExpectations($this->data, [