From 2a9fd5fb62f5521d358011b6256497650234336b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 27 Dec 2016 22:20:25 -0500 Subject: [PATCH] Disable automatically a feed after too many failures --- ChangeLog | 1 + app/constants.php | 1 + app/handlers/feed.php | 4 +++- app/schemas/postgres.php | 2 +- app/templates/feed_items.php | 2 +- app/templates/feeds.php | 2 +- config.default.php | 3 +++ docs/config.markdown | 3 +++ 8 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3c88d1..bf5230f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ Version 1.2.0 (unreleased) * Always update feed URL to avoid useless redirections for futures requests * Add support for Wallabag service * Show last parsing error message in user interface +* Disable automatically a feed after too many failures * Add unit tests Migration procedure from 1.1.x to 1.2.0: diff --git a/app/constants.php b/app/constants.php index f3c7347..bbeae31 100644 --- a/app/constants.php +++ b/app/constants.php @@ -33,6 +33,7 @@ defined('PROXY_USERNAME') or define('PROXY_USERNAME', ''); defined('PROXY_PASSWORD') or define('PROXY_PASSWORD', ''); defined('SUBSCRIPTION_CONCURRENT_REQUESTS') or define('SUBSCRIPTION_CONCURRENT_REQUESTS', 5); +defined('SUBSCRIPTION_DISABLE_THRESHOLD_ERROR') or define('SUBSCRIPTION_DISABLE_THRESHOLD_ERROR', 10); defined('RULES_DIRECTORY') or define('RULES_DIRECTORY', ROOT_DIRECTORY.DIRECTORY_SEPARATOR.'rules'); diff --git a/app/handlers/feed.php b/app/handlers/feed.php index b004019..c0f6897 100644 --- a/app/handlers/feed.php +++ b/app/handlers/feed.php @@ -104,10 +104,12 @@ function update_feed($user_id, $feed_id) ); if (! empty($error_message)) { + $error_count = $subscription['parsing_error'] + 1; Model\Feed\update_feed($user_id, $feed_id, array( 'last_checked' => time(), - 'parsing_error' => 1, + 'parsing_error' => $error_count, 'parsing_error_message' => $error_message, + 'enabled' => $error_count > SUBSCRIPTION_DISABLE_THRESHOLD_ERROR ? 0 : 1, )); return false; diff --git a/app/schemas/postgres.php b/app/schemas/postgres.php index 3f57b06..f342f13 100644 --- a/app/schemas/postgres.php +++ b/app/schemas/postgres.php @@ -47,7 +47,7 @@ function version_1(PDO $pdo) etag VARCHAR(255), enabled BOOLEAN DEFAULT TRUE, download_content BOOLEAN DEFAULT FALSE, - parsing_error BOOLEAN DEFAULT FALSE, + parsing_error INTEGER DEFAULT 0, rtl BOOLEAN DEFAULT FALSE, cloak_referrer BOOLEAN DEFAULT FALSE, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, diff --git a/app/templates/feed_items.php b/app/templates/feed_items.php index 05a940c..859043a 100644 --- a/app/templates/feed_items.php +++ b/app/templates/feed_items.php @@ -22,7 +22,7 @@ - + 0): ?>

diff --git a/app/templates/feeds.php b/app/templates/feeds.php index 52b7b32..0d52be4 100644 --- a/app/templates/feeds.php +++ b/app/templates/feeds.php @@ -23,7 +23,7 @@
-
> +
0 ? 'data-feed-error="1"' : '' ?>>

diff --git a/config.default.php b/config.default.php index 2f98edc..444e93f 100644 --- a/config.default.php +++ b/config.default.php @@ -55,6 +55,9 @@ define('PROXY_PASSWORD', ''); // Reduce this number on systems with limited processing power define('SUBSCRIPTION_CONCURRENT_REQUESTS', 5); +// Disable automatically a feed after X parsing failure +define('SUBSCRIPTION_DISABLE_THRESHOLD_ERROR', 10); + // Allow the cronjob to be accessible from the browser define('ENABLE_CRONJOB_HTTP_ACCESS', true); diff --git a/docs/config.markdown b/docs/config.markdown index 53c15b2..f05584d 100644 --- a/docs/config.markdown +++ b/docs/config.markdown @@ -104,6 +104,9 @@ define('PROXY_PASSWORD', ''); // Reduce this number on systems with limited processing power define('SUBSCRIPTION_CONCURRENT_REQUESTS', 5); +// Disable automatically a feed after X parsing failure +define('SUBSCRIPTION_DISABLE_THRESHOLD_ERROR', 10); + // Allow the cronjob to be accessible from the browser define('ENABLE_CRONJOB_HTTP_ACCESS', true);