remove COUNTERS_MAX_AGE, add some optimization for counter queries (refs #464)

This commit is contained in:
Andrew Dolgov 2012-07-09 13:02:42 +04:00
parent 18f6961a65
commit 687bb90d27
4 changed files with 23 additions and 60 deletions

View File

@ -864,8 +864,6 @@ class Feeds extends Protected_Handler {
else
$order_by_qpart = "title";
$age_qpart = getMaxAgeSubquery();
$query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
cat_id,last_error,

View File

@ -178,11 +178,6 @@
define('CHECK_FOR_NEW_VERSION', true);
// Check for new versions of tt-rss automatically.
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('ENABLE_GZIP_OUTPUT', false);
// Selectively gzip output to improve wire performance. This requires
// PHP Zlib extension on the server.

View File

@ -1494,8 +1494,6 @@
array_push($ret_arr, $cv);
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT id AS cat_id, value AS unread
FROM ttrss_feed_categories, ttrss_cat_counters_cache
WHERE ttrss_cat_counters_cache.feed_id = id AND
@ -1532,8 +1530,6 @@
$cat_query = "cat_id IS NULL";
}
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
AND owner_uid = " . $owner_uid);
@ -1547,9 +1543,9 @@
$match_part = implode(" OR ", $cat_feeds);
$result = db_query($link, "SELECT COUNT(int_id) AS unread
FROM ttrss_user_entries,ttrss_entries
WHERE unread = true AND ($match_part) AND id = ref_id
AND $age_qpart AND owner_uid = " . $owner_uid);
FROM ttrss_user_entries
WHERE unread = true AND ($match_part)
AND owner_uid = " . $owner_uid);
$unread = 0;
@ -1565,10 +1561,8 @@
$result = db_query($link, "
SELECT COUNT(unread) AS unread FROM
ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
ttrss_labels2.owner_uid = '$owner_uid'
AND unread = true AND feed_id = ttrss_feeds.id
ttrss_user_entries, ttrss_user_labels2
WHERE article_id = ref_id AND unread = true
AND ttrss_user_entries.owner_uid = '$owner_uid'");
$unread = db_fetch_result($result, 0, "unread");
@ -1578,16 +1572,6 @@
}
}
function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) {
if (DB_TYPE == "pgsql") {
return "ttrss_entries.date_updated >
NOW() - INTERVAL '$days days'";
} else {
return "ttrss_entries.date_updated >
DATE_SUB(NOW(), INTERVAL $days DAY)";
}
}
function getFeedUnread($link, $feed, $is_cat = false) {
return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
}
@ -1595,13 +1579,8 @@
function getLabelUnread($link, $label_id, $owner_uid = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
$result = db_query($link, "
SELECT COUNT(unread) AS unread FROM
ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
ttrss_labels2.owner_uid = '$owner_uid' AND ttrss_labels2.id = '$label_id'
AND unread = true AND feed_id = ttrss_feeds.id
AND ttrss_user_entries.owner_uid = '$owner_uid'");
$result = "SELECT COUNT(ref_id) FROM ttrss_user_entries, ttrss_user_labels2
WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id";
if (db_num_rows($result) != 0) {
return db_fetch_result($result, 0, "unread");
@ -1614,6 +1593,7 @@
$owner_uid = false) {
$n_feed = (int) $feed;
$need_entries = false;
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
@ -1623,8 +1603,6 @@
$unread_qpart = "true";
}
$age_qpart = getMaxAgeSubquery();
if ($is_cat) {
return getCategoryUnread($link, $n_feed, $owner_uid);
} if ($feed != "0" && $n_feed == 0) {
@ -1633,8 +1611,7 @@
$result = db_query($link, "SELECT SUM((SELECT COUNT(int_id)
FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
AND ref_id = id AND $age_qpart
AND $unread_qpart)) AS count FROM ttrss_tags
AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
WHERE owner_uid = $owner_uid AND tag_name = '$feed'");
return db_fetch_result($result, 0, "count");
@ -1652,6 +1629,9 @@
} else {
$match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
}
$need_entries = true;
} else if ($n_feed == -4) {
$match_part = "true";
} else if ($n_feed >= 0) {
@ -1672,20 +1652,18 @@
if ($match_part) {
if ($n_feed != 0) {
$from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries";
$feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
} else {
if ($need_entries) {
$from_qpart = "ttrss_user_entries,ttrss_entries";
$feeds_qpart = '';
$from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND";
} else {
$from_qpart = "ttrss_user_entries";
}
$query = "SELECT count(int_id) AS unread
FROM $from_qpart WHERE
ttrss_user_entries.ref_id = ttrss_entries.id AND
$age_qpart AND
$feeds_qpart
$unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
$unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
//echo "[$feed/$query]\n";
$result = db_query($link, $query);
@ -1694,8 +1672,7 @@
$result = db_query($link, "SELECT COUNT(post_int_id) AS unread
FROM ttrss_tags,ttrss_user_entries,ttrss_entries
WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id
AND $unread_qpart AND $age_qpart AND
ttrss_tags.owner_uid = " . $owner_uid);
AND $unread_qpart AND ttrss_tags.owner_uid = " . $owner_uid);
}
$unread = db_fetch_result($result, 0, "unread");
@ -1746,12 +1723,9 @@
$ret_arr = array();
$age_qpart = getMaxAgeSubquery();
$result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(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 ref_id = id AND unread = true)) AS count FROM ttrss_tags
WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
ORDER BY count DESC LIMIT 55");
@ -1799,8 +1773,6 @@
$ret_arr = array();
$age_qpart = getMaxAgeSubquery();
$owner_uid = $_SESSION["uid"];
$result = db_query($link, "SELECT id, caption FROM ttrss_labels2
@ -1832,8 +1804,6 @@
$ret_arr = array();
$age_qpart = getMaxAgeSubquery();
$query = "SELECT ttrss_feeds.id,
ttrss_feeds.title,
".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,

View File

@ -1,3 +1,3 @@
<?php # This file has been generated at: Thu Jan 12 12:16:17 MSK 2012
<?php # This file has been generated at: Mon Jul 9 12:33:19 MSK 2012
define('GENERATED_CONFIG_CHECK', 25);
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'DEFAULT_UPDATE_METHOD', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'AUTO_CREATE_USER', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'CHECK_FOR_NEW_VERSION', 'COUNTERS_MAX_AGE', 'ENABLE_GZIP_OUTPUT', 'FEEDBACK_URL', 'ARTICLE_BUTTON_PLUGINS', 'CONFIG_VERSION'); ?>
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'DEFAULT_UPDATE_METHOD', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'AUTO_CREATE_USER', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'FEEDBACK_URL', 'ARTICLE_BUTTON_PLUGINS', 'CONFIG_VERSION'); ?>