From d06cc8267bb7dfadd3693260af8788aa990a304e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 7 Dec 2020 16:59:48 +0300 Subject: [PATCH] queryFeedHeadlines: bring back DISTINCT for a limited set of columns --- classes/feeds.php | 31 ++++++++++++++++++++----------- js/App.js | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 2a929a6ad..c66fe0207 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -1774,20 +1774,24 @@ class Feeds extends Handler_Protected { if (DB_TYPE == "pgsql") { $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; + + $distinct_columns = str_replace("desc", "", strtolower($order_by)); + $distinct_qpart = "DISTINCT ON (id, $distinct_columns)"; } else { $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND"; $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; + $distinct_qpart = "DISTINCT"; //fallback } if (!$search && !$skip_first_id_check) { // if previous topmost article id changed that means our current pagination is no longer valid - $query = "SELECT - ttrss_feeds.title, - date_entered, - $yyiw_qpart, - guid, + $query = "SELECT $distinct_qpart ttrss_entries.id, + date_entered, + $yyiw_qpart, + guid, ttrss_entries.title, + ttrss_feeds.title, updated, score, marked, @@ -1806,9 +1810,9 @@ class Feeds extends Handler_Protected { $sanity_interval_qpart $first_id_query_strategy_part ORDER BY $order_by LIMIT 1"; - /*if ($_REQUEST["debug"]) { - print $query; - }*/ + if ($_REQUEST["debug"]) { + print "\n*** FIRST ID QUERY ***\n$query\n"; + } $res = $pdo->query($query); @@ -1821,11 +1825,12 @@ class Feeds extends Handler_Protected { } } - $query = "SELECT + $query = "SELECT $distinct_qpart + ttrss_entries.id AS id, date_entered, $yyiw_qpart, guid, - ttrss_entries.id,ttrss_entries.title, + ttrss_entries.title, updated, label_cache, tag_cache, @@ -1857,12 +1862,16 @@ class Feeds extends Handler_Protected { //if ($_REQUEST["debug"]) print $query; + if ($_REQUEST["debug"]) { + print "\n*** HEADLINES QUERY ***\n$query\n"; + } + $res = $pdo->query($query); } else { // browsing by tag - $query = "SELECT + $query = "SELECT $distinct_qpart date_entered, guid, note, diff --git a/js/App.js b/js/App.js index 31e812925..9170e7f0c 100644 --- a/js/App.js +++ b/js/App.js @@ -1049,7 +1049,7 @@ const App = { //Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), viewfeed_debug: true}); App.postOpenWindow("backend.php", {op: "feeds", method: "view", - feed: Feeds.getActive(), timestamps: 1, is_cat: Feeds.activeIsCat(), csrf_token: __csrf_token}); + feed: Feeds.getActive(), timestamps: 1, debug: 1, is_cat: Feeds.activeIsCat(), csrf_token: __csrf_token}); }; this.hotkey_actions["feed_edit"] = () => {