Separate cleanup from update_adaptive

Cleanup processes all feeds, update_adaptive only those with an URL.
Also moved marking items as old to cleanup.
This commit is contained in:
Peter J. Holzer 2018-02-19 10:03:36 +01:00
parent d3466e4420
commit a324ce4a65
3 changed files with 15 additions and 15 deletions

View File

@ -165,20 +165,10 @@ sub update {
}
}
} else {
print "<p>unknown type $self->{type}</p>\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});
}

View File

@ -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");
}

View File

@ -9,3 +9,4 @@ BEGIN { Log::Log4perl->init("log.conf") };
my $feedlist = Rss2Html::FeedList->new();
$feedlist->update_adaptive;
$feedlist->cleanup;