queryFeedHeadlines: bring back DISTINCT for a limited set of columns

This commit is contained in:
Andrew Dolgov 2020-12-07 16:59:48 +03:00
parent e40b79ab33
commit d06cc8267b
2 changed files with 21 additions and 12 deletions

View File

@ -1774,20 +1774,24 @@ class Feeds extends Handler_Protected {
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
$sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND";
$yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; $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 { } else {
$sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND"; $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND";
$yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw";
$distinct_qpart = "DISTINCT"; //fallback
} }
if (!$search && !$skip_first_id_check) { if (!$search && !$skip_first_id_check) {
// if previous topmost article id changed that means our current pagination is no longer valid // if previous topmost article id changed that means our current pagination is no longer valid
$query = "SELECT $query = "SELECT $distinct_qpart
ttrss_feeds.title,
date_entered,
$yyiw_qpart,
guid,
ttrss_entries.id, ttrss_entries.id,
date_entered,
$yyiw_qpart,
guid,
ttrss_entries.title, ttrss_entries.title,
ttrss_feeds.title,
updated, updated,
score, score,
marked, marked,
@ -1806,9 +1810,9 @@ class Feeds extends Handler_Protected {
$sanity_interval_qpart $sanity_interval_qpart
$first_id_query_strategy_part ORDER BY $order_by LIMIT 1"; $first_id_query_strategy_part ORDER BY $order_by LIMIT 1";
/*if ($_REQUEST["debug"]) { if ($_REQUEST["debug"]) {
print $query; print "\n*** FIRST ID QUERY ***\n$query\n";
}*/ }
$res = $pdo->query($query); $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, date_entered,
$yyiw_qpart, $yyiw_qpart,
guid, guid,
ttrss_entries.id,ttrss_entries.title, ttrss_entries.title,
updated, updated,
label_cache, label_cache,
tag_cache, tag_cache,
@ -1857,12 +1862,16 @@ class Feeds extends Handler_Protected {
//if ($_REQUEST["debug"]) print $query; //if ($_REQUEST["debug"]) print $query;
if ($_REQUEST["debug"]) {
print "\n*** HEADLINES QUERY ***\n$query\n";
}
$res = $pdo->query($query); $res = $pdo->query($query);
} else { } else {
// browsing by tag // browsing by tag
$query = "SELECT $query = "SELECT $distinct_qpart
date_entered, date_entered,
guid, guid,
note, note,

View File

@ -1049,7 +1049,7 @@ const App = {
//Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), viewfeed_debug: true}); //Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), viewfeed_debug: true});
App.postOpenWindow("backend.php", {op: "feeds", method: "view", 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"] = () => { this.hotkey_actions["feed_edit"] = () => {