From 25ea280502fbb0fb7fc51f355df8fc644dfc994d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 27 Oct 2010 12:05:20 +0400 Subject: [PATCH] add ttrss_entries.date_updated; use date_updated instead of date_enered for expiry checking (bump schema) --- backend.php | 4 ++-- functions.php | 40 ++++++++++++++++++----------------- sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 3 ++- schema/ttrss_schema_pgsql.sql | 5 +++-- schema/versions/mysql/67.sql | 5 +++++ schema/versions/pgsql/67.sql | 9 ++++++++ utils/xml-export.php | 4 ++-- utils/xml-import.php | 6 +++--- 9 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 schema/versions/mysql/67.sql create mode 100644 schema/versions/pgsql/67.sql diff --git a/backend.php b/backend.php index 2dd3c5c9b..4b2202ce8 100644 --- a/backend.php +++ b/backend.php @@ -319,9 +319,9 @@ switch ($order_by) { case "date": if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "date_entered"; + $override_order = "date_updated"; } else { - $override_order = "date_entered DESC"; + $override_order = "date_updated DESC"; } break; diff --git a/functions.php b/functions.php index dda8d894f..981923573 100644 --- a/functions.php +++ b/functions.php @@ -174,7 +174,7 @@ if (DB_TYPE == "pgsql") { /* $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 + (SELECT date_updated FROM ttrss_entries WHERE id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */ $pg_version = get_pgsql_version($link); @@ -186,7 +186,7 @@ marked = false AND feed_id = '$feed_id' AND $query_limit - ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); + ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); } else { @@ -196,7 +196,7 @@ marked = false AND feed_id = '$feed_id' AND $query_limit - ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); + ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); } $rows = pg_affected_rows($result); @@ -205,7 +205,7 @@ /* $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 + (SELECT date_updated FROM ttrss_entries WHERE id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ $result = db_query($link, "DELETE FROM ttrss_user_entries @@ -214,7 +214,7 @@ marked = false AND feed_id = '$feed_id' AND $query_limit - ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); + ttrss_entries.date_updated < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); $rows = mysql_affected_rows($link); @@ -1105,6 +1105,7 @@ content, content_hash, no_orig_date, + date_updated, date_entered, comments, num_comments, @@ -1117,19 +1118,20 @@ '$entry_content', '$content_hash', $no_orig_date, - NOW(), + NOW(), + NOW(), '$entry_comments', '$num_comments', '$entry_author')"); } else { // we keep encountering the entry in feeds, so we need to - // update date_entered column so that we don't get horrible + // update date_updated column so that we don't get horrible // dupes when the entry gets purged and reinserted again e.g. // in the case of SLOW SLOW OMG SLOW updating feeds $base_entry_id = db_fetch_result($result, 0, "id"); - db_query($link, "UPDATE ttrss_entries SET date_entered = NOW() + db_query($link, "UPDATE ttrss_entries SET date_updated = NOW() WHERE id = '$base_entry_id'"); } @@ -1137,7 +1139,7 @@ $result = db_query($link, "SELECT id,content_hash,no_orig_date,title, - ".SUBSTRING_FOR_DATE."(date_entered,1,19) as date_entered, + ".SUBSTRING_FOR_DATE."(date_updated,1,19) as date_updated, ".SUBSTRING_FOR_DATE."(updated,1,19) as updated, num_comments FROM @@ -1157,8 +1159,8 @@ $orig_content_hash = db_fetch_result($result, 0, "content_hash"); $orig_title = db_fetch_result($result, 0, "title"); $orig_num_comments = db_fetch_result($result, 0, "num_comments"); - $orig_date_entered = strtotime(db_fetch_result($result, - 0, "date_entered")); + $orig_date_updated = strtotime(db_fetch_result($result, + 0, "date_updated")); $ref_id = db_fetch_result($result, 0, "id"); $entry_ref_id = $ref_id; @@ -2563,10 +2565,10 @@ function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) { if (DB_TYPE == "pgsql") { - return "ttrss_entries.date_entered > + return "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; } else { - return "ttrss_entries.date_entered > + return "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; } } @@ -3576,7 +3578,7 @@ } $query = "SELECT DISTINCT - date_entered, + date_updated, guid, ttrss_entries.id,ttrss_entries.title, updated, @@ -3646,7 +3648,7 @@ if (!$limit) $limit = 30; $qfh_ret = queryFeedHeadlines($link, $feed, - $limit, false, $is_cat, $search, $search_mode, $match_on, "date_entered DESC", 0, + $limit, false, $is_cat, $search, $search_mode, $match_on, "date_updated DESC", 0, $owner_uid); $result = $qfh_ret[0]; @@ -3888,14 +3890,14 @@ $affected_ids = array(); if (DB_TYPE == "pgsql") { - $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'"; + $interval_query = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; } else if (DB_TYPE == "mysql") { - $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)"; + $interval_query = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; } $result = db_query($link, "SELECT ttrss_entries.title, ttrss_feeds.title AS feed_title, - date_entered, + date_updated, ttrss_user_entries.ref_id, link, SUBSTRING(content, 1, 120) AS excerpt, @@ -3908,7 +3910,7 @@ AND $interval_query AND ttrss_user_entries.owner_uid = $user_id AND unread = true - ORDER BY ttrss_feeds.title, date_entered DESC + ORDER BY ttrss_feeds.title, date_updated DESC LIMIT $limit"); $cur_feed_title = ""; diff --git a/sanity_check.php b/sanity_check.php index b0d7477c7..363c22661 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 19); - define('SCHEMA_VERSION', 66); + define('SCHEMA_VERSION', 67); if (!file_exists("config.php")) { print "Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 0f4acf900..84eb985d1 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -134,6 +134,7 @@ create table ttrss_entries (id integer not null primary key auto_increment, content_hash varchar(250) not null, no_orig_date bool not null default 0, date_entered datetime not null, + date_updated datetime not null, num_comments integer not null default 0, comments varchar(250) not null default '', author varchar(250) not null default '') TYPE=InnoDB; @@ -240,7 +241,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) TYPE=InnoDB; -insert into ttrss_version values (66); +insert into ttrss_version values (67); 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 7225f10f8..ea5465dac 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -117,7 +117,8 @@ create table ttrss_entries (id serial not null primary key, content text not null, content_hash varchar(250) not null, no_orig_date boolean not null default false, - date_entered timestamp not null default NOW(), + date_entered timestamp not null, + date_updated timestamp not null, num_comments integer not null default 0, comments varchar(250) not null default '', author varchar(250) not null default ''); @@ -212,7 +213,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (66); +insert into ttrss_version values (67); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/schema/versions/mysql/67.sql b/schema/versions/mysql/67.sql new file mode 100644 index 000000000..b501bf4c3 --- /dev/null +++ b/schema/versions/mysql/67.sql @@ -0,0 +1,5 @@ +alter table ttrss_entries add column date_updated datetime; +update ttrss_entries set date_updated = date_entered; +alter table ttrss_entries change date_updated date_updated datetime not null; + +update ttrss_version set schema_version = 67; diff --git a/schema/versions/pgsql/67.sql b/schema/versions/pgsql/67.sql new file mode 100644 index 000000000..1e2aa4429 --- /dev/null +++ b/schema/versions/pgsql/67.sql @@ -0,0 +1,9 @@ +begin; + +alter table ttrss_entries add column date_updated timestamp; +update ttrss_entries set date_updated = date_entered; +alter table ttrss_entries alter column date_updated set not null; + +update ttrss_version set schema_version = 67; + +commit; diff --git a/utils/xml-export.php b/utils/xml-export.php index 438f008d4..6926fd6c2 100644 --- a/utils/xml-export.php +++ b/utils/xml-export.php @@ -97,7 +97,7 @@ updated, guid, link, - SUBSTRING(date_entered,1,16) AS date_entered, + SUBSTRING(date_updated,1,16) AS date_updated, SUBSTRING(last_read,1,16) AS last_read, comments, ttrss_feeds.feed_url AS feed_url, @@ -118,7 +118,7 @@ updated, guid, link, - SUBSTRING(date_entered,1,16) AS date_entered, + SUBSTRING(date_updated,1,16) AS date_updated, SUBSTRING(last_read,1,16) AS last_read, comments, ttrss_feeds.feed_url AS feed_url, diff --git a/utils/xml-import.php b/utils/xml-import.php index 0706b0fa2..96201d91e 100644 --- a/utils/xml-import.php +++ b/utils/xml-import.php @@ -63,7 +63,7 @@ $entry_guid = db_escape_string($data["guid"]); $entry_link = db_escape_string($data["link"]); $updated = db_escape_string($data["updated"]); - $date_entered = db_escape_string($data["date_entered"]); + $date_updated = db_escape_string($data["date_updated"]); $entry_content = db_escape_string($data["content"]); $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); $entry_comments = db_escape_string($data["comments"]); @@ -77,7 +77,7 @@ content, content_hash, no_orig_date, - date_entered, + date_updated, comments) VALUES ('$entry_title', @@ -87,7 +87,7 @@ '$entry_content', '$content_hash', false, - '$date_entered', + '$date_updated', '$entry_comments')"); }