]> git.wh0rd.org Git - tt-rss.git/commitdiff
remove COUNTERS_MAX_AGE, add some optimization for counter queries (refs #464)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 9 Jul 2012 09:02:42 +0000 (13:02 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 9 Jul 2012 09:02:42 +0000 (13:02 +0400)
classes/feeds.php
config.php-dist
include/functions.php
include/sanity_config.php

index 1e2d566968adbbdaffc847e85289273db2023806..0c9812479a86069b53e1251b56f5a1b86961b69f 100644 (file)
@@ -864,8 +864,6 @@ class Feeds extends Protected_Handler {
                else\r
                        $order_by_qpart = "title";\r
 \r
-               $age_qpart = getMaxAgeSubquery();\r
-\r
                $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,\r
                        ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,\r
                        cat_id,last_error,\r
index cffb00d0fe3ca70919b851d5d68e670e1e094f24..b71307dafc2db265ea1659a477c26ed82664a9bb 100644 (file)
        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.
index 4a1ba42e267ab29364675549aa8a81d85f993d75..1e527e70db0f735c627ce3ab0ad13932a34ddb4e 100644 (file)
 
                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
                                $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);
 
                        $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;
 
 
                        $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");
                }
        }
 
-       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"]);
        }
        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");
                $owner_uid = false) {
 
                $n_feed = (int) $feed;
+               $need_entries = false;
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                        $unread_qpart = "true";
                }
 
-               $age_qpart = getMaxAgeSubquery();
-
                if ($is_cat) {
                        return getCategoryUnread($link, $n_feed, $owner_uid);
                } if ($feed != "0" && $n_feed == 0) {
 
                        $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");
 
                        } 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) {
 
                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);
 
                        $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");
 
                $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");
 
 
                $ret_arr = array();
 
-               $age_qpart = getMaxAgeSubquery();
-
                $owner_uid = $_SESSION["uid"];
 
                $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
 
                $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,
index dfeffbd6e6821975a4b4474a91163bf9fd452328..f56e3bdbed20e2f924a61c2b222a9ae9077cabd9 100644 (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'); ?>