]> git.wh0rd.org Git - tt-rss.git/commitdiff
new option: COUNTERS_MAX_AGE (2)
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 25 Aug 2007 03:34:33 +0000 (04:34 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 25 Aug 2007 03:34:33 +0000 (04:34 +0100)
config.php-dist
functions.php

index 3f48c5420d2d8cc6d3ddce373ec610ae8c78cecb..0cd257beddac488ccdeb365ec0cd562364f966ae 100644 (file)
        // to any feeds using HTTP Digest authentication and Magpie XML parsing 
        // 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);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).
index 89863f06c3e92e6de232e24cb44aabd42548697d..86d591420d921988c4345664d6c502927ef59d6c 100644 (file)
 
                print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>";
 
+               $age_qpart = getMaxAgeSubquery();
+
                $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 
                        WHERE 
                                hidden = false AND owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
                        } else {
                                $cat_query = "cat_id IS NULL";
                        }
-       
+
+                       $age_qpart = getMaxAgeSubquery();
+
                        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query 
                                        AND hidden = false
                                        AND owner_uid = " . $_SESSION["uid"]);
                        $match_part = implode(" OR ", $cat_feeds);
        
                        $result = db_query($link, "SELECT COUNT(int_id) AS unread 
-                               FROM ttrss_user_entries 
-                               WHERE   unread = true AND ($match_part) AND owner_uid = " . $_SESSION["uid"]);
+                               FROM ttrss_user_entries,ttrss_entries 
+                               WHERE   unread = true AND ($match_part) AND id = ref_id 
+                               AND $age_qpart AND owner_uid = " . $_SESSION["uid"]);
        
                        $unread = 0;
        
                }
        }
 
+       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) {
                $n_feed = sprintf("%d", $feed);
 
+               $age_qpart = getMaxAgeSubquery();
+
                if ($is_cat) {
                        return getCategoryUnread($link, $n_feed);               
                } else if ($n_feed == -1) {
                                $match_part = implode(" OR ", $linked_feeds);
 
                                $result = db_query($link, "SELECT COUNT(int_id) AS unread 
-                                       FROM ttrss_user_entries
-                                       WHERE   unread = true AND ($match_part) 
-                                       AND owner_uid = " . $_SESSION["uid"]);
+                                       FROM ttrss_user_entries,ttrss_entries
+                                       WHERE   unread = true AND
+                                       ttrss_user_entries.ref_id = ttrss_entries.id AND
+                                       $age_qpart AND
+                                       ($match_part) AND
+                                       owner_uid = " . $_SESSION["uid"]);
 
                                $unread = 0;
 
                                ttrss_user_entries.feed_id = ttrss_feeds.id AND
                                ttrss_user_entries.ref_id = ttrss_entries.id AND 
                                ttrss_feeds.hidden = false AND
+                               $age_qpart AND
                                unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
                                
                } else {
                
                        $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
-                               FROM ttrss_tags,ttrss_user_entries 
-                               WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
+                               FROM ttrss_tags,ttrss_user_entries,ttrss_entries 
+                               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"]);
                }
                
                        $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
                        WHERE unread = true AND 
                        ttrss_user_entries.feed_id = ttrss_feeds.id AND
                        ttrss_user_entries.ref_id = ttrss_entries.id AND 
                        hidden = false AND
+                       $age_qpart AND
                        ttrss_user_entries.owner_uid = '$user_id'");
                $c_id = db_fetch_result($result, 0, "c_id");
                return $c_id;
                        select tag_name,0 as count FROM ttrss_tags
                        WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
 
+               $age_qpart = getMaxAgeSubquery();
+
                $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 
                                WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name 
                                ORDER BY count DESC LIMIT 55");
 
        function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) {
 
+               $age_qpart = getMaxAgeSubquery();
+
                if ($smart_mode) {
                        if (!$_SESSION["lctr_last_value"]) {
                                $_SESSION["lctr_last_value"] = array();
                        $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 
                                ttrss_feeds.hidden = false AND
+                               $age_qpart AND
                                ttrss_user_entries.feed_id = ttrss_feeds.id AND
                                ttrss_user_entries.ref_id = ttrss_entries.id AND 
                                ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
 
        function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
 
+               $age_qpart = getMaxAgeSubquery();
+
                if ($smart_mode) {
                        if (!$_SESSION["fctr_last_value"]) {
                                $_SESSION["fctr_last_value"] = array();
                        FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
                        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, 
                                last_error, 
                                COUNT(ttrss_entries.id) AS count 
                                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.unread = true) 
-                               LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id) 
-                       WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
+                               LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND
+                                       $age_qpart) 
+                       WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."  
                                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;
 
                $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
                        $has_img = is_file(ICONS_DIR . "/$id.ico");
 
                        $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 
                                        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) {                             
                                while ($l = db_fetch_assoc($tmp_result)) {
                                }
                        }
 
+                       $age_qpart = getMaxAgeSubquery();
+
                        $result = db_query($link, "SELECT ttrss_feeds.*,
                                SUBSTRING(last_updated,1,19) AS last_updated_noms,
                                (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
                                        WHERE feed_id = ttrss_feeds.id AND unread = true
+                                               AND $age_qpart
                                                AND ttrss_user_entries.ref_id = ttrss_entries.id
                                                AND owner_uid = '$owner_uid') as unread,
                                cat_id,last_error,
                                print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
                        }
 
+                       $age_qpart = getMaxAgeSubquery();
+
                        $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 
                                        WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name 
                                        ORDER BY count DESC LIMIT 50");