]> git.wh0rd.org Git - tt-rss.git/commitdiff
speedup feed subscription process
authorAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 20:11:47 +0000 (23:11 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 20:11:47 +0000 (23:11 +0300)
include/functions.php
include/rssfuncs.php

index 0d4c8ed09cd6dd4a9e1a06f3eb843c8001a2e86f..edc196f314baeafae610d520a13ce2dae1629e16 100644 (file)
                        $feed_id = db_fetch_result($result, 0, "id");
 
                        if ($feed_id) {
-                               update_rss_feed($feed_id, true);
+                               set_basic_feed_info($feed_id);
                        }
 
                        return array("code" => 1);
index 4dbb7c18e427b4a46bad7e014fda58611bf07dbf..33f9ebb87ffdcc94789c10bd6e9d737b3460ad83 100644 (file)
 
        } // function update_daemon_common
 
+       // this is used when subscribing
+       function set_basic_feed_info($feed) {
+
+               $feed = db_escape_string($feed);
+
+               $result = db_query("SELECT feed_url,auth_pass,auth_pass_encrypted
+                                       FROM ttrss_feeds WHERE id = '$feed'");
+
+               $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result,
+                       0, "auth_pass_encrypted"));
+
+               $auth_login = db_fetch_result($result, 0, "auth_login");
+               $auth_pass = db_fetch_result($result, 0, "auth_pass");
+
+               if ($auth_pass_encrypted) {
+                       require_once "crypt.php";
+                       $auth_pass = decrypt_string($auth_pass);
+               }
+
+               $fetch_url = db_fetch_result($result, 0, "feed_url");
+
+               $feed_data = fetch_file_contents($fetch_url, false,
+                       $auth_login, $auth_pass, false,
+                       FEED_FETCH_TIMEOUT_TIMEOUT,
+                       0);
+
+               global $fetch_curl_used;
+
+               if (!$fetch_curl_used) {
+                       $tmp = @gzdecode($feed_data);
+
+                       if ($tmp) $feed_data = $tmp;
+               }
+
+               $feed_data = trim($feed_data);
+
+               $rss = new FeedParser($feed_data);
+               $rss->init();
+
+               if (!$rss->error()) {
+
+                       $result = db_query("SELECT title, site_url FROM ttrss_feeds WHERE id = '$feed'");
+
+                       $registered_title = db_fetch_result($result, 0, "title");
+                       $orig_site_url = db_fetch_result($result, 0, "site_url");
+
+                       $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245));
+                       $feed_title = db_escape_string(mb_substr($rss->get_title(), 0, 199));
+
+                       if ($feed_title && (!$registered_title || $registered_title == "[Unknown]")) {
+                               db_query("UPDATE ttrss_feeds SET
+                                       title = '$feed_title' WHERE id = '$feed'");
+                       }
+
+                       if ($site_url && $orig_site_url != $site_url) {
+                               db_query("UPDATE ttrss_feeds SET
+                                                       site_url = '$site_url' WHERE id = '$feed'");
+                       }
+               }
+       }
+
        // ignore_daemon is not used
        function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false, $rss = false) {