summaryrefslogtreecommitdiff
path: root/update_daemon2.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_daemon2.php
parentc29324c7a4d35c6feac3ff7d2557a265e0c4cc35 (diff)
daemons: only select feeds which require update (patch from landure)
Diffstat (limited to 'update_daemon2.php')
-rw-r--r--update_daemon2.php94
1 files changed, 46 insertions, 48 deletions
diff --git a/update_daemon2.php b/update_daemon2.php
index 326b69e49..4d2eed5d9 100644
--- a/update_daemon2.php
+++ b/update_daemon2.php
@@ -79,7 +79,6 @@
pcntl_signal(SIGALRM, 'sigalrm_handler');
pcntl_signal(SIGCHLD, 'sigchld_handler');
- pcntl_signal(SIGINT, 'sigint_handler');
if (file_is_locked("update_daemon.lock")) {
die("error: Can't create lockfile. ".
@@ -92,6 +91,8 @@
}
if (!pcntl_fork()) {
+ pcntl_signal(SIGINT, 'sigint_handler');
+
$lock_handle = make_lockfile("update_daemon.lock");
if (!$lock_handle) {
@@ -198,26 +199,49 @@
$login_thresh_qpart = "";
}
+ //if (DB_TYPE == "pgsql") {
+ // $update_limit_qpart = "AND ttrss_feeds.last_updated < NOW() - INTERVAL '".(DAEMON_SLEEP_INTERVAL*2)." seconds'";
+ //} else {
+ // $update_limit_qpart = "AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ".(DAEMON_SLEEP_INTERVAL*2)." SECOND)";
+ //}
+
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") {
- $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')";
- } else {
- $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))";
- }
+ $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')";
+ } else {
+ $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();
@@ -241,48 +265,18 @@
while ($line = array_pop($feeds_to_update)) {
- $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)) {
-
- _debug("Updating...");
-
- pcntl_alarm(300);
+ pcntl_alarm(300);
+ update_rss_feed($link, $line["feed_url"], $line["id"], true);
+ pcntl_alarm(0);
- 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);
- print "Elapsed time: " . (time() - $start_timestamp) . " second(s)\n";
+ _debug("Elapsed time: " . (time() - $start_timestamp) . " second(s)");
db_close($link);
@@ -292,6 +286,10 @@
// We exit in order to avoid fork bombing.
exit(0);
}
+
+ // We wait a little time before the next fork, in order to let the first fork
+ // mark the feeds it update :
+ sleep(1);
}
$last_checkpoint = time();
}