]> git.wh0rd.org Git - tt-rss.git/commitdiff
query optimizations; split big feed update transaction
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 21 Mar 2006 04:52:56 +0000 (05:52 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 21 Mar 2006 04:52:56 +0000 (05:52 +0100)
functions.php
schema/ttrss_schema_pgsql.sql
update_daemon.php

index 69decc65cb34157ef09cdb6c0f57fed3abd44005..f0d6aa05e60f862bb61b4828507aaca6e432a918 100644 (file)
                $rows = -1;
 
                if (DB_TYPE == "pgsql") {
-                       $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
+/*                     $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE
                                marked = false AND feed_id = '$feed_id' AND
                                (SELECT date_entered FROM ttrss_entries WHERE
-                                       id = ref_id) < NOW() - INTERVAL '$purge_interval days'");
+                                       id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */
+
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE 
+                               ttrss_entries.id = ref_id AND 
+                               marked = false AND 
+                               feed_id = '$feed_id' AND 
+                               ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'");
 
                        $rows = pg_affected_rows($result);
                        
                }
        }
 
-       function global_purge_old_posts($link, $do_output = false) {
+       function global_purge_old_posts($link, $do_output = false, $limit = false) {
+
+               if (DB_TYPE == "mysql") {
+                       $random_qpart = "RAND()";
+               } else {
+                       $random_qpart = "RANDOM()";
+               }
 
+               if ($limit) {
+                       $limit_qpart = "LIMIT $limit";
+               } else {
+                       $limit_qpart = "";
+               }
+               
                $result = db_query($link, 
-                       "SELECT id,purge_interval,owner_uid FROM ttrss_feeds ORDER BY id");
+                       "SELECT id,purge_interval,owner_uid FROM ttrss_feeds 
+                               ORDER BY $random_qpart $limit_qpart");
 
                while ($line = db_fetch_assoc($result)) {
 
 
                if ($rss) {
 
-                       db_query($link, "BEGIN");
+//                     db_query($link, "BEGIN");
 
                        $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
                                FROM ttrss_feeds WHERE id = '$feed'");
 
                                if (!$num_comments) $num_comments = 0;
 
+                               db_query($link, "BEGIN");
+
                                if (db_num_rows($result) == 0) {
 
                                        // base post entry does not exist, create it
                                        }
                                }
 
+                               db_query($link, "COMMIT");
+
                                /* taaaags */
                                // <a href="http://technorati.com/tag/Xorg" rel="tag">Xorg</a>, //
 
 
                                if (count($entry_tags) > 0) {
                                
+                                       db_query($link, "BEGIN");
+                       
                                        $result = db_query($link, "SELECT id,int_id 
                                                FROM ttrss_entries,ttrss_user_entries 
                                                WHERE guid = '$entry_guid' 
                                                        }                                                       
                                                }
                                        }
+                                       db_query($link, "COMMIT");
                                } 
                        } 
 
                        db_query($link, "UPDATE ttrss_feeds 
                                SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
 
-                       db_query($link, "COMMIT");
+//                     db_query($link, "COMMIT");
 
                } else {
                        $error_msg = db_escape_string(magpie_error());
index 7013228fb6339a7421cbacb102f7f22fe8a5baf6..a4a711078e22d069c968d1a09e4c5498688a228d 100644 (file)
@@ -83,6 +83,7 @@ create table ttrss_entries (id serial not null primary key,
 
 create index ttrss_entries_guid_index on ttrss_entries(guid);
 create index ttrss_entries_title_index on ttrss_entries(title);
+create index ttrss_entries_date_entered_index on ttrss_entries(date_entered);
 
 create table ttrss_user_entries (
        int_id serial not null primary key,
index da94050fc31ea7f23b064ee0d94ef64e009b7cf2..cf51bdd3abfe090ff28a76e438bffd7bc458fa37 100644 (file)
                $result = db_query($link, "SELECT feed_url,id,owner_uid,
                        SUBSTRING(last_updated,1,19) AS last_updated,
                        update_interval FROM ttrss_feeds ORDER BY last_updated DESC");
-       
+
+               $user_prefs_cache = array();
+
                while ($line = db_fetch_assoc($result)) {
        
                        $upd_intl = $line["update_interval"];
                        $user_id = $line["owner_uid"];
        
                        if (!$upd_intl || $upd_intl == 0) {
-                               $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
+                               if (!$user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']) {                  
+                                       $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id);
+                                       $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'] = $upd_intl;
+                               } else {
+                                       $upd_intl = $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'];
+                               }
                        }
 
                        if ($upd_intl < 0) { 
        
                                print "Updating...\n";  
                                update_rss_feed($link, $line["feed_url"], $line["id"], true);   
-                               sleep(3); // prevent flood (FIXME make this an option?)
+                               sleep(1); // prevent flood (FIXME make this an option?)
                        } else {
                                print "Update not needed.\n";
                        }