Browse Source

Lasts tests for icon cache; fixes #177

rpm
J. King 3 years ago
parent
commit
b62c11a43e
  1. 2
      lib/Database.php
  2. 40
      tests/cases/Database/SeriesCleanup.php

2
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) {

40
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, [

Loading…
Cancel
Save