remove COUNTERS_MAX_AGE, add some optimization for counter queries (refs #464)
This commit is contained in:
parent
18f6961a65
commit
687bb90d27
4 changed files with 23 additions and 60 deletions
|
@ -864,8 +864,6 @@ class Feeds extends Protected_Handler {
|
||||||
else
|
else
|
||||||
$order_by_qpart = "title";
|
$order_by_qpart = "title";
|
||||||
|
|
||||||
$age_qpart = getMaxAgeSubquery();
|
|
||||||
|
|
||||||
$query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
|
$query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
|
||||||
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
|
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
|
||||||
cat_id,last_error,
|
cat_id,last_error,
|
||||||
|
|
|
@ -178,11 +178,6 @@
|
||||||
define('CHECK_FOR_NEW_VERSION', true);
|
define('CHECK_FOR_NEW_VERSION', true);
|
||||||
// Check for new versions of tt-rss automatically.
|
// 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);
|
define('ENABLE_GZIP_OUTPUT', false);
|
||||||
// Selectively gzip output to improve wire performance. This requires
|
// Selectively gzip output to improve wire performance. This requires
|
||||||
// PHP Zlib extension on the server.
|
// PHP Zlib extension on the server.
|
||||||
|
|
|
@ -1494,8 +1494,6 @@
|
||||||
|
|
||||||
array_push($ret_arr, $cv);
|
array_push($ret_arr, $cv);
|
||||||
|
|
||||||
$age_qpart = getMaxAgeSubquery();
|
|
||||||
|
|
||||||
$result = db_query($link, "SELECT id AS cat_id, value AS unread
|
$result = db_query($link, "SELECT id AS cat_id, value AS unread
|
||||||
FROM ttrss_feed_categories, ttrss_cat_counters_cache
|
FROM ttrss_feed_categories, ttrss_cat_counters_cache
|
||||||
WHERE ttrss_cat_counters_cache.feed_id = id AND
|
WHERE ttrss_cat_counters_cache.feed_id = id AND
|
||||||
|
@ -1532,8 +1530,6 @@
|
||||||
$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 owner_uid = " . $owner_uid);
|
AND owner_uid = " . $owner_uid);
|
||||||
|
|
||||||
|
@ -1547,9 +1543,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,ttrss_entries
|
FROM ttrss_user_entries
|
||||||
WHERE unread = true AND ($match_part) AND id = ref_id
|
WHERE unread = true AND ($match_part)
|
||||||
AND $age_qpart AND owner_uid = " . $owner_uid);
|
AND owner_uid = " . $owner_uid);
|
||||||
|
|
||||||
$unread = 0;
|
$unread = 0;
|
||||||
|
|
||||||
|
@ -1565,10 +1561,8 @@
|
||||||
|
|
||||||
$result = db_query($link, "
|
$result = db_query($link, "
|
||||||
SELECT COUNT(unread) AS unread FROM
|
SELECT COUNT(unread) AS unread FROM
|
||||||
ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
|
ttrss_user_entries, ttrss_user_labels2
|
||||||
WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
|
WHERE article_id = ref_id AND unread = true
|
||||||
ttrss_labels2.owner_uid = '$owner_uid'
|
|
||||||
AND unread = true AND feed_id = ttrss_feeds.id
|
|
||||||
AND ttrss_user_entries.owner_uid = '$owner_uid'");
|
AND ttrss_user_entries.owner_uid = '$owner_uid'");
|
||||||
|
|
||||||
$unread = db_fetch_result($result, 0, "unread");
|
$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) {
|
function getFeedUnread($link, $feed, $is_cat = false) {
|
||||||
return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
|
return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
|
||||||
}
|
}
|
||||||
|
@ -1595,13 +1579,8 @@
|
||||||
function getLabelUnread($link, $label_id, $owner_uid = false) {
|
function getLabelUnread($link, $label_id, $owner_uid = false) {
|
||||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||||
|
|
||||||
$result = db_query($link, "
|
$result = "SELECT COUNT(ref_id) FROM ttrss_user_entries, ttrss_user_labels2
|
||||||
SELECT COUNT(unread) AS unread FROM
|
WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id";
|
||||||
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'");
|
|
||||||
|
|
||||||
if (db_num_rows($result) != 0) {
|
if (db_num_rows($result) != 0) {
|
||||||
return db_fetch_result($result, 0, "unread");
|
return db_fetch_result($result, 0, "unread");
|
||||||
|
@ -1614,6 +1593,7 @@
|
||||||
$owner_uid = false) {
|
$owner_uid = false) {
|
||||||
|
|
||||||
$n_feed = (int) $feed;
|
$n_feed = (int) $feed;
|
||||||
|
$need_entries = false;
|
||||||
|
|
||||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||||
|
|
||||||
|
@ -1623,8 +1603,6 @@
|
||||||
$unread_qpart = "true";
|
$unread_qpart = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
$age_qpart = getMaxAgeSubquery();
|
|
||||||
|
|
||||||
if ($is_cat) {
|
if ($is_cat) {
|
||||||
return getCategoryUnread($link, $n_feed, $owner_uid);
|
return getCategoryUnread($link, $n_feed, $owner_uid);
|
||||||
} if ($feed != "0" && $n_feed == 0) {
|
} if ($feed != "0" && $n_feed == 0) {
|
||||||
|
@ -1633,8 +1611,7 @@
|
||||||
|
|
||||||
$result = db_query($link, "SELECT SUM((SELECT COUNT(int_id)
|
$result = db_query($link, "SELECT SUM((SELECT COUNT(int_id)
|
||||||
FROM ttrss_user_entries,ttrss_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 ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
|
||||||
AND $unread_qpart)) AS count FROM ttrss_tags
|
|
||||||
WHERE owner_uid = $owner_uid AND tag_name = '$feed'");
|
WHERE owner_uid = $owner_uid AND tag_name = '$feed'");
|
||||||
return db_fetch_result($result, 0, "count");
|
return db_fetch_result($result, 0, "count");
|
||||||
|
|
||||||
|
@ -1652,6 +1629,9 @@
|
||||||
} else {
|
} else {
|
||||||
$match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
|
$match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$need_entries = true;
|
||||||
|
|
||||||
} else if ($n_feed == -4) {
|
} else if ($n_feed == -4) {
|
||||||
$match_part = "true";
|
$match_part = "true";
|
||||||
} else if ($n_feed >= 0) {
|
} else if ($n_feed >= 0) {
|
||||||
|
@ -1672,20 +1652,18 @@
|
||||||
|
|
||||||
if ($match_part) {
|
if ($match_part) {
|
||||||
|
|
||||||
if ($n_feed != 0) {
|
if ($need_entries) {
|
||||||
$from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries";
|
|
||||||
$feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
|
|
||||||
} else {
|
|
||||||
$from_qpart = "ttrss_user_entries,ttrss_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
|
$query = "SELECT count(int_id) AS unread
|
||||||
FROM $from_qpart WHERE
|
FROM $from_qpart WHERE
|
||||||
ttrss_user_entries.ref_id = ttrss_entries.id AND
|
$unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
|
||||||
$age_qpart AND
|
|
||||||
$feeds_qpart
|
//echo "[$feed/$query]\n";
|
||||||
$unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
|
|
||||||
|
|
||||||
$result = db_query($link, $query);
|
$result = db_query($link, $query);
|
||||||
|
|
||||||
|
@ -1694,8 +1672,7 @@
|
||||||
$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,ttrss_entries
|
FROM ttrss_tags,ttrss_user_entries,ttrss_entries
|
||||||
WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id
|
WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id
|
||||||
AND $unread_qpart AND $age_qpart AND
|
AND $unread_qpart AND ttrss_tags.owner_uid = " . $owner_uid);
|
||||||
ttrss_tags.owner_uid = " . $owner_uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$unread = db_fetch_result($result, 0, "unread");
|
$unread = db_fetch_result($result, 0, "unread");
|
||||||
|
@ -1746,12 +1723,9 @@
|
||||||
|
|
||||||
$ret_arr = array();
|
$ret_arr = array();
|
||||||
|
|
||||||
$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,ttrss_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 ref_id = id 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");
|
||||||
|
|
||||||
|
@ -1799,8 +1773,6 @@
|
||||||
|
|
||||||
$ret_arr = array();
|
$ret_arr = array();
|
||||||
|
|
||||||
$age_qpart = getMaxAgeSubquery();
|
|
||||||
|
|
||||||
$owner_uid = $_SESSION["uid"];
|
$owner_uid = $_SESSION["uid"];
|
||||||
|
|
||||||
$result = db_query($link, "SELECT id, caption FROM ttrss_labels2
|
$result = db_query($link, "SELECT id, caption FROM ttrss_labels2
|
||||||
|
@ -1832,8 +1804,6 @@
|
||||||
|
|
||||||
$ret_arr = array();
|
$ret_arr = array();
|
||||||
|
|
||||||
$age_qpart = getMaxAgeSubquery();
|
|
||||||
|
|
||||||
$query = "SELECT ttrss_feeds.id,
|
$query = "SELECT ttrss_feeds.id,
|
||||||
ttrss_feeds.title,
|
ttrss_feeds.title,
|
||||||
".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
|
".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
|
||||||
|
|
|
@ -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);
|
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'); ?>
|
||||||
|
|
Loading…
Reference in a new issue