daemons: only select feeds which require update (patch from landure)

This commit is contained in:
Andrew Dolgov 2008-01-24 18:35:26 +01:00
parent c29324c7a4
commit 0d6a7147e5
2 changed files with 75 additions and 91 deletions

View File

@ -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))";
}
$result = db_query($link, "SELECT feed_url,ttrss_feeds.id,owner_uid,
SUBSTRING(last_updated,1,19) AS last_updated,
update_interval
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))";
}
$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));
pcntl_alarm(300);
update_rss_feed($link, $line["feed_url"], $line["id"], true);
pcntl_alarm(0);
if (!$line["last_updated"] ||
time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
_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);
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();
}

View File

@ -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));
pcntl_alarm(300);
update_rss_feed($link, $line["feed_url"], $line["id"], true);
pcntl_alarm(0);
if (!$line["last_updated"] ||
time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
_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);