summaryrefslogtreecommitdiff
path: root/update_daemon_loop.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2008-01-24 18:35:26 +0100
committerAndrew Dolgov <[email protected]>2008-01-24 18:35:26 +0100
commit0d6a7147e5b82cdf2c973c5efd3e5415fdc0287b (patch)
tree5aabeddae7270a5ed61d1c0380cdc59a2c25751d /update_daemon_loop.php
parentc29324c7a4d35c6feac3ff7d2557a265e0c4cc35 (diff)
daemons: only select feeds which require update (patch from landure)
Diffstat (limited to 'update_daemon_loop.php')
-rw-r--r--update_daemon_loop.php70
1 files changed, 28 insertions, 42 deletions
diff --git a/update_daemon_loop.php b/update_daemon_loop.php
index 1f7e9184e..08fad1b97 100644
--- a/update_daemon_loop.php
+++ b/update_daemon_loop.php
@@ -117,8 +117,21 @@
if (DB_TYPE == "pgsql") {
$update_limit_qpart = "AND ttrss_feeds.last_updated < NOW() - INTERVAL '".(DAEMON_SLEEP_INTERVAL*2)." seconds'";
+ $update_limit_qpart = "AND ((
+ ttrss_feeds.update_interval = 0
+ AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_user_prefs.value || ' minutes'
+ ) OR (
+ ttrss_feeds.update_interval > 0
+ AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_feeds.update_interval || ' minutes'
+ ))";
} else {
- $update_limit_qpart = "AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ".(DAEMON_SLEEP_INTERVAL*2)." SECOND)";
+ $update_limit_qpart = "AND ((
+ ttrss_feeds.update_interval = 0
+ AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
+ ) OR (
+ ttrss_feeds.update_interval > 0
+ AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
+ ))";
}
if (DB_TYPE == "pgsql") {
@@ -127,14 +140,17 @@
$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))";
}
- $result = db_query($link, "SELECT feed_url,ttrss_feeds.id,owner_uid,
- SUBSTRING(last_updated,1,19) AS last_updated,
- update_interval
+ $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid,
+ SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated,
+ ttrss_feeds.update_interval
FROM
- ttrss_feeds,ttrss_users
- WHERE
- ttrss_users.id = owner_uid $login_thresh_qpart $update_limit_qpart
- $updstart_thresh_qpart
+ ttrss_feeds, ttrss_users, ttrss_user_prefs
+ WHERE
+ ttrss_feeds.owner_uid = ttrss_users.id
+ AND ttrss_users.id = ttrss_user_prefs.owner_uid
+ AND ttrss_user_prefs.pref_name='DEFAULT_UPDATE_INTERVAL'
+ $login_thresh_qpart $update_limit_qpart
+ $updstart_thresh_qpart
ORDER BY $random_qpart DESC LIMIT " . DAEMON_FEED_LIMIT);
$user_prefs_cache = array();
@@ -143,43 +159,13 @@
while ($line = db_fetch_assoc($result)) {
- $upd_intl = $line["update_interval"];
- $user_id = $line["owner_uid"];
-
- if (!$upd_intl || $upd_intl == 0) {
- if (!$user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']) {
- $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
- $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'] = $upd_intl;
- } else {
- $upd_intl = $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'];
- }
- }
-
- if ($upd_intl < 0) {
-# print "Updates disabled.\n";
- continue;
- }
-
_debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]);
-// _debug(sprintf("\tLU: %d, INTL: %d, UID: %d) ",
-// time() - strtotime($line["last_updated"]), $upd_intl*60, $user_id));
-
- if (!$line["last_updated"] ||
- time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
+ pcntl_alarm(300);
+ update_rss_feed($link, $line["feed_url"], $line["id"], true);
+ pcntl_alarm(0);
- _debug("Updating...");
-
- pcntl_alarm(300);
-
- update_rss_feed($link, $line["feed_url"], $line["id"], true);
-
- pcntl_alarm(0);
-
- sleep(1); // prevent flood (FIXME make this an option?)
- } else {
- _debug("Update not needed.");
- }
+ sleep(1); // prevent flood (FIXME make this an option?)
}
if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link);