From 3120ee83f0cc99d91115d60387f167ac20424d35 Mon Sep 17 00:00:00 2001 From: Dysosmus Date: Wed, 27 Mar 2013 12:58:30 +0100 Subject: [PATCH 1/4] Add 'mark read' shortcut. --- miniflux/templates/read_item.php | 2 +- miniflux/templates/unread_items.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/miniflux/templates/read_item.php b/miniflux/templates/read_item.php index 170d2ee..099d097 100644 --- a/miniflux/templates/read_item.php +++ b/miniflux/templates/read_item.php @@ -3,7 +3,7 @@

Article not found.

- +

diff --git a/miniflux/templates/unread_items.php b/miniflux/templates/unread_items.php index decc987..5c79283 100644 --- a/miniflux/templates/unread_items.php +++ b/miniflux/templates/unread_items.php @@ -15,12 +15,14 @@ From 8d984fc1c14fa9c8cf15fb3a76512b4ea086012e Mon Sep 17 00:00:00 2001 From: Dysosmus Date: Sat, 18 May 2013 20:35:16 +0200 Subject: [PATCH 2/4] Improved cronjob --- README.markdown | 19 +++++++++++++++++-- miniflux/common.php | 12 ++++++++---- miniflux/model.php | 36 +++++++++++++++++++++++++++--------- miniflux/schema.php | 4 ++++ 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/README.markdown b/README.markdown index a0e2548..cd7de1f 100644 --- a/README.markdown +++ b/README.markdown @@ -67,13 +67,28 @@ FAQ ### How to update your feeds with a cronjob? -You just need to be inside the directory `miniflux` and run the script `cronjob.php`. +You just need to be inside the directory `miniflux` and run the script `cronjob.php`. -By example: +Prameters | Type | Value +-------------------|--------------------------------|----------------------------- +--limit | optional |time in minutes +--call-interval | optional, exclude by --limit, requires --update-interval |time in minutes < update inteval time +--update-interval | optional, exclude by --limit, requires --call-interval |time in minutes >= call interval time + + +Examples: crontab -e 0 */4 * * * cd /path/to/miniflux && php cronjob.php >/dev/null 2>&1 + + # Updates the 10 oldest feeds each time + + 0 */4 * * * cd /path/to/miniflux && php cronjob.php --limit=10 >/dev/null 2>&1 + + # Updates all feeds in 60mn (updates the 8 oldest feeds each time with a total of 120 feeds). + + 0 */4 * * * cd /path/to/miniflux && php cronjob.php --call-interval=4 --update-interval=60 >/dev/null 2>&1 ### How Miniflux update my feeds from the user interface? diff --git a/miniflux/common.php b/miniflux/common.php index 7c0e222..e41803b 100644 --- a/miniflux/common.php +++ b/miniflux/common.php @@ -10,17 +10,21 @@ require 'schema.php'; require 'model.php'; -const DB_VERSION = 4; -const APP_VERSION = 'master'; +const DB_VERSION = 5; +const APP_VERSION = 'master'; const APP_USERAGENT = 'Miniflux - http://miniflux.net'; -const HTTP_TIMEOUT = 5; - +const HTTP_TIMEOUT = 5; +const LIMIT_ALL = -1; function get_db_filename() { return 'data/db.sqlite'; } +function is_console() +{ + return php_sapi_name() === 'cli'; +} PicoTools\container('db', function() { diff --git a/miniflux/model.php b/miniflux/model.php index 2bcf339..f95be1e 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -107,10 +107,11 @@ function import_feed($url) return false; } - -function update_feeds() +function update_feeds($limit = LIMIT_ALL) { - foreach (get_feeds_id() as $feed_id) { + $feeds_id = get_feeds_id($limit); + + foreach ($feeds_id as $feed_id) { update_feed($feed_id); } @@ -134,6 +135,8 @@ function update_feed($feed_id) APP_USERAGENT ); + update_feed_last_checked($feed_id); + if (! $resource->isModified()) { return true; @@ -158,12 +161,18 @@ function update_feed($feed_id) } -function get_feeds_id() +function get_feeds_id($limit = LIMIT_ALL) { - return \PicoTools\singleton('db') - ->table('feeds') - ->asc('updated') - ->listing('id', 'id'); + $table_feeds = \PicoTools\singleton('db')->table('feeds') + ->desc('last_checked'); + + if($limit !== LIMIT_ALL) { + + $table_feeds->limit((int)$limit); + } + + return $table_feeds->listing('id', 'id'); + } @@ -184,6 +193,14 @@ function get_feed($feed_id) ->findOne(); } +function update_feed_last_checked($feed_id) { + \PicoTools\singleton('db') + ->table('feeds') + ->eq('id', $feed_id) + ->save(array( + 'last_checked' => time(), + )); +} function update_feed_cache_infos($feed_id, $last_modified, $etag) { @@ -192,7 +209,8 @@ function update_feed_cache_infos($feed_id, $last_modified, $etag) ->eq('id', $feed_id) ->save(array( 'last_modified' => $last_modified, - 'etag' => $etag + 'etag' => $etag, + 'last_checked' => time(), )); } diff --git a/miniflux/schema.php b/miniflux/schema.php index 4007577..9907b10 100644 --- a/miniflux/schema.php +++ b/miniflux/schema.php @@ -2,6 +2,10 @@ namespace Schema; +function version_5($pdo) +{ + $pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER'); +} function version_4($pdo) { From 6234f45407ff2f32315f1336af017088e1d2234c Mon Sep 17 00:00:00 2001 From: Dysosmus Date: Sat, 18 May 2013 20:35:16 +0200 Subject: [PATCH 3/4] Improved cronjob --- README.markdown | 19 +++++++++++++++++-- miniflux/common.php | 12 ++++++++---- miniflux/cronjob.php | 21 +++++++++++++++++++-- miniflux/model.php | 36 +++++++++++++++++++++++++++--------- miniflux/schema.php | 4 ++++ 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/README.markdown b/README.markdown index a0e2548..cd7de1f 100644 --- a/README.markdown +++ b/README.markdown @@ -67,13 +67,28 @@ FAQ ### How to update your feeds with a cronjob? -You just need to be inside the directory `miniflux` and run the script `cronjob.php`. +You just need to be inside the directory `miniflux` and run the script `cronjob.php`. -By example: +Prameters | Type | Value +-------------------|--------------------------------|----------------------------- +--limit | optional |time in minutes +--call-interval | optional, exclude by --limit, requires --update-interval |time in minutes < update inteval time +--update-interval | optional, exclude by --limit, requires --call-interval |time in minutes >= call interval time + + +Examples: crontab -e 0 */4 * * * cd /path/to/miniflux && php cronjob.php >/dev/null 2>&1 + + # Updates the 10 oldest feeds each time + + 0 */4 * * * cd /path/to/miniflux && php cronjob.php --limit=10 >/dev/null 2>&1 + + # Updates all feeds in 60mn (updates the 8 oldest feeds each time with a total of 120 feeds). + + 0 */4 * * * cd /path/to/miniflux && php cronjob.php --call-interval=4 --update-interval=60 >/dev/null 2>&1 ### How Miniflux update my feeds from the user interface? diff --git a/miniflux/common.php b/miniflux/common.php index 7c0e222..e41803b 100644 --- a/miniflux/common.php +++ b/miniflux/common.php @@ -10,17 +10,21 @@ require 'schema.php'; require 'model.php'; -const DB_VERSION = 4; -const APP_VERSION = 'master'; +const DB_VERSION = 5; +const APP_VERSION = 'master'; const APP_USERAGENT = 'Miniflux - http://miniflux.net'; -const HTTP_TIMEOUT = 5; - +const HTTP_TIMEOUT = 5; +const LIMIT_ALL = -1; function get_db_filename() { return 'data/db.sqlite'; } +function is_console() +{ + return php_sapi_name() === 'cli'; +} PicoTools\container('db', function() { diff --git a/miniflux/cronjob.php b/miniflux/cronjob.php index 796240e..b85920b 100644 --- a/miniflux/cronjob.php +++ b/miniflux/cronjob.php @@ -1,5 +1,22 @@ = $call_interval) { + + $feeds_count = \PicoTools\singleton('db')->table('feeds')->count(); + $limit = ceil($feeds_count / ( $update_interval / $call_interval )) ; // compute new limit + } + + Model\update_feeds($limit); +} diff --git a/miniflux/model.php b/miniflux/model.php index 2bcf339..f95be1e 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -107,10 +107,11 @@ function import_feed($url) return false; } - -function update_feeds() +function update_feeds($limit = LIMIT_ALL) { - foreach (get_feeds_id() as $feed_id) { + $feeds_id = get_feeds_id($limit); + + foreach ($feeds_id as $feed_id) { update_feed($feed_id); } @@ -134,6 +135,8 @@ function update_feed($feed_id) APP_USERAGENT ); + update_feed_last_checked($feed_id); + if (! $resource->isModified()) { return true; @@ -158,12 +161,18 @@ function update_feed($feed_id) } -function get_feeds_id() +function get_feeds_id($limit = LIMIT_ALL) { - return \PicoTools\singleton('db') - ->table('feeds') - ->asc('updated') - ->listing('id', 'id'); + $table_feeds = \PicoTools\singleton('db')->table('feeds') + ->desc('last_checked'); + + if($limit !== LIMIT_ALL) { + + $table_feeds->limit((int)$limit); + } + + return $table_feeds->listing('id', 'id'); + } @@ -184,6 +193,14 @@ function get_feed($feed_id) ->findOne(); } +function update_feed_last_checked($feed_id) { + \PicoTools\singleton('db') + ->table('feeds') + ->eq('id', $feed_id) + ->save(array( + 'last_checked' => time(), + )); +} function update_feed_cache_infos($feed_id, $last_modified, $etag) { @@ -192,7 +209,8 @@ function update_feed_cache_infos($feed_id, $last_modified, $etag) ->eq('id', $feed_id) ->save(array( 'last_modified' => $last_modified, - 'etag' => $etag + 'etag' => $etag, + 'last_checked' => time(), )); } diff --git a/miniflux/schema.php b/miniflux/schema.php index 4007577..9907b10 100644 --- a/miniflux/schema.php +++ b/miniflux/schema.php @@ -2,6 +2,10 @@ namespace Schema; +function version_5($pdo) +{ + $pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER'); +} function version_4($pdo) { From 3c95af8a432dffba5491652853cb54d49adcf4bb Mon Sep 17 00:00:00 2001 From: Dysosmus Date: Sat, 18 May 2013 21:47:22 +0200 Subject: [PATCH 4/4] Fix bug (wrong order in get_feeds_id) --- miniflux/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniflux/model.php b/miniflux/model.php index f95be1e..8365a2d 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -164,7 +164,7 @@ function update_feed($feed_id) function get_feeds_id($limit = LIMIT_ALL) { $table_feeds = \PicoTools\singleton('db')->table('feeds') - ->desc('last_checked'); + ->asc('last_checked'); if($limit !== LIMIT_ALL) {