From a324ce4a654e4dd00619e55657c0ba81c8c8ab58 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Mon, 19 Feb 2018 10:03:36 +0100 Subject: [PATCH] Separate cleanup from update_adaptive Cleanup processes all feeds, update_adaptive only those with an URL. Also moved marking items as old to cleanup. --- lib/Rss2Html/Feed.pm | 12 +----------- lib/Rss2Html/FeedList.pm | 17 +++++++++++++---- update3 | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/Rss2Html/Feed.pm b/lib/Rss2Html/Feed.pm index fec5aa6..4f4d0f7 100644 --- a/lib/Rss2Html/Feed.pm +++ b/lib/Rss2Html/Feed.pm @@ -165,20 +165,10 @@ sub update { } } } else { - print "

unknown type $self->{type}

\n"; - $dbh->do("update feeds set title=?, last_update=? where id=?", {}, - 'unknown', $now, $self->{id}); + $self->log->info("ignoring feed type $self->{type} of feed #$self->{id}: $self->{title}"); return; } - # mark all but the last 100 entries as old, so they aren't shown by default. - $dbh->do("update items set old=1 - where id in (select id from items - where feed_id=? and (old is null or old != 1) - order by issued desc offset 100)", - {}, - $self->{id}); - $dbh->do("update feeds set last_update=? where id=?", {}, $now, $self->{id}); } diff --git a/lib/Rss2Html/FeedList.pm b/lib/Rss2Html/FeedList.pm index 3a209cf..ca74c37 100644 --- a/lib/Rss2Html/FeedList.pm +++ b/lib/Rss2Html/FeedList.pm @@ -27,7 +27,7 @@ sub feeds { no autovivification qw(fetch); - my $feeds_sql = $dbh->selectall_arrayref("select * from feeds where active", { Slice => {} }); + my $feeds_sql = $dbh->selectall_arrayref("select * from feeds where active and url is not null", { Slice => {} }); my @feeds; for (@$feeds_sql) { push @feeds, Rss2Html::Feed->new(%$_, dbh => $dbh); @@ -97,8 +97,6 @@ sub update_adaptive { $feed->update; } } - $self->cleanup(); - $dbh->commit; $self->log->info("update done"); @@ -117,8 +115,19 @@ sub cleanup { my $seen_limit = $now - $expire_days * 86400; my $rc = $dbh->do("delete from items where feed_id=? and seen < ?", {}, $feed->{id}, $seen_limit); $self->log->info("cleanup of feed $feed->{id} (limit $seen_limit) returned $rc"); + + # mark all but the last 100 entries as old, so they aren't shown by default. + $dbh->do("update items set old=1 + where id in (select id from items + where feed_id=? and (old is null or old != 1) + order by issued desc offset 100)", + {}, + $feed->{id}); + } - $dbh->do("delete from read where not exists (select id from items where id=item_id)"); + # XXX - this shouldn't be necessary anymore, since PostgreSQL enforces foreign key constraints. + my $rc = $dbh->do("delete from read where not exists (select id from items where id=item_id)"); + $self->log->info("cleanup of read items returned $rc"); } diff --git a/update3 b/update3 index b53c9c1..0205c76 100755 --- a/update3 +++ b/update3 @@ -9,3 +9,4 @@ BEGIN { Log::Log4perl->init("log.conf") }; my $feedlist = Rss2Html::FeedList->new(); $feedlist->update_adaptive; +$feedlist->cleanup;