From: Andrew Dolgov Date: Thu, 24 May 2012 12:20:03 +0000 (+0400) Subject: rate-limit requests for favicons when not present to conserve traffic (refs #457) X-Git-Tag: 1.6.0~227 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=382268c6c9f778e7b435ee69c56a9407d9e8dcc2;p=tt-rss.git rate-limit requests for favicons when not present to conserve traffic (refs #457) --- diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 84a24e2f..9c01c905 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -414,12 +414,22 @@ // 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"); @@ -441,7 +451,7 @@ _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]") { @@ -1285,7 +1295,9 @@ 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"); diff --git a/include/sanity_check.php b/include/sanity_check.php index 26d699be..11da8592 100644 --- a/include/sanity_check.php +++ b/include/sanity_check.php @@ -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"; diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index c75d0086..54f53e85 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 2d3c963c..35b5c440 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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 index 00000000..8ebe81fe --- /dev/null +++ b/schema/versions/mysql/92.sql @@ -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 index 00000000..b683d514 --- /dev/null +++ b/schema/versions/pgsql/92.sql @@ -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;