]> git.wh0rd.org Git - tt-rss.git/commitdiff
rate-limit requests for favicons when not present to conserve traffic (refs #457)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 24 May 2012 12:20:03 +0000 (16:20 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 24 May 2012 12:20:03 +0000 (16:20 +0400)
include/rssfuncs.php
include/sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/92.sql [new file with mode: 0644]
schema/versions/pgsql/92.sql [new file with mode: 0644]

index 84a24e2f00b26cceb69d8fc5c7a66ea37faec25d..9c01c9056b22e476b255109c727024e834403708 100644 (file)
 
 //                     db_query($link, "BEGIN");
 
-                       $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid
+                       if (DB_TYPE == "pgsql") {
+                               $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
+                       } else {
+                               $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
+                       }
+
+                       $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid,
+                               (favicon_last_checked IS NULL OR $favicon_interval_qpart) AS
+                                               favicon_needs_check
                                FROM ttrss_feeds WHERE id = '$feed'");
 
                        $registered_title = db_fetch_result($result, 0, "title");
                        $orig_icon_url = db_fetch_result($result, 0, "icon_url");
                        $orig_site_url = db_fetch_result($result, 0, "site_url");
+                       $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0,
+                               "favicon_needs_check"));
 
                        $owner_uid = db_fetch_result($result, 0, "owner_uid");
 
                                _debug("update_rss_feed: checking favicon...");
                        }
 
-                       check_feed_favicon($site_url, $feed, $link);
+                       if ($favicon_needs_check) check_feed_favicon($site_url, $feed, $link);
 
                        if (!$registered_title || $registered_title == "[Unknown]") {
 
                        purge_feed($link, $feed, 0, $debug_enabled);
 
                        db_query($link, "UPDATE ttrss_feeds
-                               SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
+                               SET last_updated = NOW(),
+                                       favicon_last_checked = NOW(),
+                                       last_error = '' WHERE id = '$feed'");
 
 //                     db_query($link, "COMMIT");
 
index 26d699be707f95dc320c4e747d13c517eb0ee15a..11da859210b57a1c5632898919eb0d9e16a0e3b6 100644 (file)
@@ -10,7 +10,7 @@
                } else {
 
                        define('EXPECTED_CONFIG_VERSION', 25);
-                       define('SCHEMA_VERSION', 91);
+                       define('SCHEMA_VERSION', 92);
 
                        require_once "config.php";
                        require_once "sanity_config.php";
index c75d008620168be63aadccd33b4c0def9166963d..54f53e85f7f9c72fb30f9e0137fca60abdb200fa 100644 (file)
@@ -119,6 +119,7 @@ create table ttrss_feeds (id integer not null auto_increment primary key,
        update_on_checksum_change boolean not null default false,
        strip_images boolean not null default false,
        pubsub_state integer not null default 0,
+       favicon_last_checked datetime default null,
        index(owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE,
        index(cat_id),
@@ -260,7 +261,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (91);
+insert into ttrss_version values (92);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
index 2d3c963ca987c22831b8b4eda40f1b08f80a3c49..35b5c440b7f0450bcf73c3a26ad7ca561b0b676e 100644 (file)
@@ -82,6 +82,7 @@ create table ttrss_feeds (id serial not null primary key,
        update_on_checksum_change boolean not null default false,
        strip_images boolean not null default false,
        pubsub_state integer not null default 0,
+       favicon_last_checked timestamp default null,
        auth_pass_encrypted boolean not null default false);
 
 create index ttrss_feeds_owner_uid_index on ttrss_feeds(owner_uid);
@@ -229,7 +230,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (91);
+insert into ttrss_version values (92);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
diff --git a/schema/versions/mysql/92.sql b/schema/versions/mysql/92.sql
new file mode 100644 (file)
index 0000000..8ebe81f
--- /dev/null
@@ -0,0 +1,8 @@
+begin;
+
+alter table ttrss_feeds add column favicon_last_checked datetime;
+alter table ttrss_feeds alter column favicon_last_checked set default null;
+
+update ttrss_version set schema_version = 92;
+
+commit;
diff --git a/schema/versions/pgsql/92.sql b/schema/versions/pgsql/92.sql
new file mode 100644 (file)
index 0000000..b683d51
--- /dev/null
@@ -0,0 +1,8 @@
+begin;
+
+alter table ttrss_feeds add column favicon_last_checked timestamp;
+alter table ttrss_feeds alter column favicon_last_checked set default null;
+
+update ttrss_version set schema_version = 92;
+
+commit;