new option: COUNTERS_MAX_AGE (2)

This commit is contained in:
Andrew Dolgov 2007-08-25 04:34:33 +01:00
parent 3a1cd1ec8e
commit 14073c0ae4
2 changed files with 66 additions and 17 deletions

View File

@ -163,6 +163,11 @@
// to any feeds using HTTP Digest authentication and Magpie XML parsing // to any feeds using HTTP Digest authentication and Magpie XML parsing
// errors are bothering you too much, you can try enabling SimplePie. // errors are bothering you too much, you can try enabling SimplePie.
define('COUNTERS_MAX_AGE', 365);
// Hard limit for unread counters calculation. Try tweaking this
// parameter to speed up tt-rss when having a huge number of articles
// in the database (better yet, enable purging!)
define('CONFIG_VERSION', 9); define('CONFIG_VERSION', 9);
// Expected config version. Please update this option in config.php // Expected config version. Please update this option in config.php
// if necessary (after migrating all new options from this file). // if necessary (after migrating all new options from this file).

View File

@ -1900,8 +1900,11 @@
print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>"; print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>";
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id FROM ttrss_user_entries, ttrss_entries WHERE feed_id = ttrss_feeds.id
AND id = ref_id AND $age_qpart
AND unread = true)) AS unread FROM ttrss_feeds AND unread = true)) AS unread FROM ttrss_feeds
WHERE WHERE
hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
@ -1923,6 +1926,8 @@
$cat_query = "cat_id IS NULL"; $cat_query = "cat_id IS NULL";
} }
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
AND hidden = false AND hidden = false
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $_SESSION["uid"]);
@ -1937,8 +1942,9 @@
$match_part = implode(" OR ", $cat_feeds); $match_part = implode(" OR ", $cat_feeds);
$result = db_query($link, "SELECT COUNT(int_id) AS unread $result = db_query($link, "SELECT COUNT(int_id) AS unread
FROM ttrss_user_entries FROM ttrss_user_entries,ttrss_entries
WHERE unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]); WHERE unread = true AND ($match_part) AND id = ref_id
AND $age_qpart AND owner_uid = " . $_SESSION["uid"]);
$unread = 0; $unread = 0;
@ -1965,9 +1971,21 @@
} }
} }
function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) {
if (DB_TYPE == "pgsql") {
return "ttrss_entries.date_entered >
NOW() - INTERVAL '$days days'";
} else {
return "ttrss_entries.date_entered >
DATE_SUB(NOW(), INTERVAL $days DAY)";
}
}
function getFeedUnread($link, $feed, $is_cat = false) { function getFeedUnread($link, $feed, $is_cat = false) {
$n_feed = sprintf("%d", $feed); $n_feed = sprintf("%d", $feed);
$age_qpart = getMaxAgeSubquery();
if ($is_cat) { if ($is_cat) {
return getCategoryUnread($link, $n_feed); return getCategoryUnread($link, $n_feed);
} else if ($n_feed == -1) { } else if ($n_feed == -1) {
@ -2004,9 +2022,12 @@
$match_part = implode(" OR ", $linked_feeds); $match_part = implode(" OR ", $linked_feeds);
$result = db_query($link, "SELECT COUNT(int_id) AS unread $result = db_query($link, "SELECT COUNT(int_id) AS unread
FROM ttrss_user_entries FROM ttrss_user_entries,ttrss_entries
WHERE unread = true AND ($match_part) WHERE unread = true AND
AND owner_uid = " . $_SESSION["uid"]); ttrss_user_entries.ref_id = ttrss_entries.id AND
$age_qpart AND
($match_part) AND
owner_uid = " . $_SESSION["uid"]);
$unread = 0; $unread = 0;
@ -2037,13 +2058,15 @@
ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
ttrss_feeds.hidden = false AND ttrss_feeds.hidden = false AND
$age_qpart AND
unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
} else { } else {
$result = db_query($link, "SELECT COUNT(post_int_id) AS unread $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
FROM ttrss_tags,ttrss_user_entries FROM ttrss_tags,ttrss_user_entries,ttrss_entries
WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = id
AND unread = true AND $age_qpart AND
ttrss_tags.owner_uid = " . $_SESSION["uid"]); ttrss_tags.owner_uid = " . $_SESSION["uid"]);
} }
@ -2060,11 +2083,14 @@
$user_id = $_SESSION["uid"]; $user_id = $_SESSION["uid"];
} }
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
WHERE unread = true AND WHERE unread = true AND
ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
hidden = false AND hidden = false AND
$age_qpart AND
ttrss_user_entries.owner_uid = '$user_id'"); ttrss_user_entries.owner_uid = '$user_id'");
$c_id = db_fetch_result($result, 0, "c_id"); $c_id = db_fetch_result($result, 0, "c_id");
return $c_id; return $c_id;
@ -2108,8 +2134,11 @@
select tag_name,0 as count FROM ttrss_tags select tag_name,0 as count FROM ttrss_tags
WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
FROM ttrss_user_entries WHERE int_id = post_int_id FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
AND ref_id = id AND $age_qpart
AND unread = true)) AS count FROM ttrss_tags AND unread = true)) AS count FROM ttrss_tags
WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
ORDER BY count DESC LIMIT 55"); ORDER BY count DESC LIMIT 55");
@ -2141,6 +2170,8 @@
function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) {
$age_qpart = getMaxAgeSubquery();
if ($smart_mode) { if ($smart_mode) {
if (!$_SESSION["lctr_last_value"]) { if (!$_SESSION["lctr_last_value"]) {
$_SESSION["lctr_last_value"] = array(); $_SESSION["lctr_last_value"] = array();
@ -2194,6 +2225,7 @@
$tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
WHERE (" . $line["sql_exp"] . ") AND unread = true AND WHERE (" . $line["sql_exp"] . ") AND unread = true AND
ttrss_feeds.hidden = false AND ttrss_feeds.hidden = false AND
$age_qpart AND
ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
@ -2238,6 +2270,8 @@
function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
$age_qpart = getMaxAgeSubquery();
if ($smart_mode) { if ($smart_mode) {
if (!$_SESSION["fctr_last_value"]) { if (!$_SESSION["fctr_last_value"]) {
$_SESSION["fctr_last_value"] = array(); $_SESSION["fctr_last_value"] = array();
@ -2256,7 +2290,8 @@
FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . " FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
AND parent_feed IS NULL"); */ AND parent_feed IS NULL"); */
$result = db_query($link, "SELECT ttrss_feeds.id, $query = "SELECT ttrss_feeds.id,
ttrss_feeds.title,
SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated, SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated,
last_error, last_error,
COUNT(ttrss_entries.id) AS count COUNT(ttrss_entries.id) AS count
@ -2264,11 +2299,13 @@
LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id
AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid
AND ttrss_user_entries.unread = true) AND ttrss_user_entries.unread = true)
LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id) LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND
$age_qpart)
WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]." WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
AND parent_feed IS NULL AND parent_feed IS NULL
GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error"); GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error";
$result = db_query($link, $query);
$fctrs_modified = false; $fctrs_modified = false;
$short_date = get_pref($link, 'SHORT_DATE_FORMAT'); $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
@ -2288,10 +2325,11 @@
$has_img = is_file(ICONS_DIR . "/$id.ico"); $has_img = is_file(ICONS_DIR . "/$id.ico");
$tmp_result = db_query($link, $tmp_result = db_query($link,
"SELECT id,COUNT(unread) AS unread "SELECT ttrss_feeds.id,COUNT(unread) AS unread
FROM ttrss_feeds LEFT JOIN ttrss_user_entries FROM ttrss_feeds LEFT JOIN ttrss_user_entries
ON (ttrss_feeds.id = ttrss_user_entries.feed_id) ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id"); LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id)
WHERE parent_feed = '$id' AND $age_qpart AND unread = true GROUP BY ttrss_feeds.id");
if (db_num_rows($tmp_result) > 0) { if (db_num_rows($tmp_result) > 0) {
while ($l = db_fetch_assoc($tmp_result)) { while ($l = db_fetch_assoc($tmp_result)) {
@ -3652,10 +3690,13 @@
} }
} }
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT ttrss_feeds.*, $result = db_query($link, "SELECT ttrss_feeds.*,
SUBSTRING(last_updated,1,19) AS last_updated_noms, SUBSTRING(last_updated,1,19) AS last_updated_noms,
(SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
WHERE feed_id = ttrss_feeds.id AND unread = true WHERE feed_id = ttrss_feeds.id AND unread = true
AND $age_qpart
AND ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id
AND owner_uid = '$owner_uid') as unread, AND owner_uid = '$owner_uid') as unread,
cat_id,last_error, cat_id,last_error,
@ -3815,8 +3856,11 @@
print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
} }
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
FROM ttrss_user_entries WHERE int_id = post_int_id FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
AND ref_id = id AND $age_qpart
AND unread = true)) AS count FROM ttrss_tags AND unread = true)) AS count FROM ttrss_tags
WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
ORDER BY count DESC LIMIT 50"); ORDER BY count DESC LIMIT 50");