From: Andrew Dolgov Date: Sat, 11 Jul 2015 22:29:36 +0000 (+0300) Subject: queryFeedHeadlines: move to array-based arguments, optionally check if first element... X-Git-Tag: 16.3~232^2~19 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f5a0fb8b64c57e98fcf73369cb4dbb1b31620fd7;p=tt-rss.git queryFeedHeadlines: move to array-based arguments, optionally check if first element changed when paginating --- diff --git a/classes/api.php b/classes/api.php index 8267572f..1a52c925 100644 --- a/classes/api.php +++ b/classes/api.php @@ -658,11 +658,30 @@ class API extends Handler { } } - $qfh_ret = queryFeedHeadlines($feed_id, $limit, + /*$qfh_ret = queryFeedHeadlines($feed_id, $limit, $view_mode, $is_cat, $search, false, - $order, $offset, 0, false, $since_id, $include_nested); - - $result = $qfh_ret[0]; + $order, $offset, 0, false, $since_id, $include_nested);*/ + + //function queryFeedHeadlines($feed, $limit, + // $view_mode, $cat_view, $search, $search_mode, + // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, + // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { + + $params = array( + "feed" => $feed_id, + "limit" => $limit, + "view_mode" => $view_mode, + "cat_view" => $is_cat, + "search" => $search, + "override_order" => $order, + "offset" => $offset, + "since_id" => $since_id, + "include_children" => $include_nested, + ); + + $qfh_ret = queryFeedHeadlines($params); + + $result = $qfh_ret[0]; $feed_title = $qfh_ret[1]; $headlines = array(); diff --git a/classes/feeds.php b/classes/feeds.php index ed66be29..15b3f068 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -148,7 +148,7 @@ class Feeds extends Handler_Protected { private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, - $override_order = false, $include_children = false) { + $override_order = false, $include_children = false, $check_top_id = false) { $disable_cache = false; @@ -232,9 +232,28 @@ class Feeds extends Handler_Protected { } } else { - $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, + /*$qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, false, $override_order, $offset, 0, - false, 0, $include_children); + false, 0, $include_children, $topid);*/ + + //function queryFeedHeadlines($feed, $limit, + // $view_mode, $cat_view, $search, $search_mode, + // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, + // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { + + $params = array( + "feed" => $feed, + "limit" => $limit, + "view_mode" => $view_mode, + "cat_view" => $cat_view, + "search" => $search, + "override_order" => $override_order, + "offset" => $offset, + "include_children" => $include_children, + "check_top_id" => $check_top_id + ); + + $qfh_ret = queryFeedHeadlines($params); } $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6; @@ -810,6 +829,7 @@ class Feeds extends Handler_Protected { @$offset = $this->dbh->escape_string($_REQUEST["skip"]); @$vgroup_last_feed = $this->dbh->escape_string($_REQUEST["vgrlf"]); $order_by = $this->dbh->escape_string($_REQUEST["order_by"]); + $check_top_id = $this->dbh->escape_string($_REQUEST["topid"]); if (is_numeric($feed)) $feed = (int) $feed; @@ -889,7 +909,7 @@ class Feeds extends Handler_Protected { $ret = $this->format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, - $vgroup_last_feed, $override_order, true); + $vgroup_last_feed, $override_order, true, $check_top_id); //$topmost_article_ids = $ret[0]; $headlines_count = $ret[1]; diff --git a/classes/handler/public.php b/classes/handler/public.php index 74e83784..1bf08870 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -37,10 +37,31 @@ class Handler_Public extends Handler { break; } - $qfh_ret = queryFeedHeadlines($feed, + /*$qfh_ret = queryFeedHeadlines($feed, 1, $view_mode, $is_cat, $search, false, $date_sort_field, $offset, $owner_uid, - false, 0, true, true, false, false, $start_ts); + false, 0, true, true, false, false, $start_ts);*/ + + //function queryFeedHeadlines($feed, + // $limit, $view_mode, $cat_view, $search, $search_mode, + // $override_order = false, $offset = 0, $owner_uid = 0, + // $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { + + $params = array( + "owner_uid" => $owner_uid, + "feed" => $feed, + "limit" => 1, + "view_mode" => $view_mode, + "cat_view" => $is_cat, + "search" => $search, + "override_order" => $date_sort_field, + "include_children" => true, + "ignore_vfeed_group" => true, + "offset" => $offset, + "start_ts" => $start_ts + ); + + $qfh_ret = queryFeedHeadlines($params); $result = $qfh_ret[0]; @@ -58,11 +79,26 @@ class Handler_Public extends Handler { header("Last-Modified: $last_modified", true); } - $qfh_ret = queryFeedHeadlines($feed, + /*$qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $is_cat, $search, false, $date_sort_field, $offset, $owner_uid, - false, 0, true, true, false, false, $start_ts); - + false, 0, true, true, false, false, $start_ts);*/ + + $params = array( + "owner_uid" => $owner_uid, + "feed" => $feed, + "limit" => $limit, + "view_mode" => $view_mode, + "cat_view" => $is_cat, + "search" => $search, + "override_order" => $date_sort_field, + "include_children" => true, + "ignore_vfeed_group" => true, + "offset" => $offset, + "start_ts" => $start_ts + ); + + $qfh_ret = queryFeedHeadlines($params); $result = $qfh_ret[0]; $feed_title = htmlspecialchars($qfh_ret[1]); @@ -496,7 +532,7 @@ class Handler_Public extends Handler { - + diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 170c1a52..5e3c35b7 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -83,9 +83,22 @@ class Pref_Filters extends Handler_Protected { } } - $qfh_ret = queryFeedHeadlines(-4, 30, "", false, false, false, - "date_entered DESC", 0, $_SESSION["uid"], $filter); - + //function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, + // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, + + /*$qfh_ret = queryFeedHeadlines(-4, 30, "", false, false, false, + "date_entered DESC", 0, $_SESSION["uid"], $filter);*/ + + $params = array( + "feed" => -4, + "limit" => 30, + "view_mode" => "", + "cat_view" => false, + "override_order" => "date_entered DESC", + "filter" => $filter + ); + + $qfh_ret = queryFeedHeadlines($params); $result = $qfh_ret[0]; $found = 0; diff --git a/include/functions2.php b/include/functions2.php index 133352f7..e4e66acd 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -426,9 +426,25 @@ } // $search_mode is obsolete/unused - function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false) { - - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + //function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { + function queryFeedHeadlines($params) { + + $feed = $params["feed"]; + $limit = isset($params["limit"]) ? $params["limit"] : 30; + $view_mode = $params["view_mode"]; + $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false; + $search = isset($params["search"]) ? $params["search"] : false; + $override_order = isset($params["override_order"]) ? $params["override_order"] : false; + $offset = isset($params["offset"]) ? $params["offset"] : 0; + $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"]; + $filter = isset($params["filter"]) ? $params["filter"] : 0; + $since_id = isset($params["since_id"]) ? $params["since_id"] : 0; + $include_children = isset($params["include_children"]) ? $params["include_children"] : false; + $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ? $params["ignore_vfeed_group"] : false; + $override_strategy = isset($params["override_strategy"]) ? $params["override_strategy"] : false; + $override_vfeed = isset($params["override_vfeed"]) ? $params["override_vfeed"] : false; + $start_ts = isset($params["start_ts"]) ? $params["start_ts"] : false; + $check_top_id = isset($params["check_top_id"]) ? $params["check_top_id"] : false; $ext_tables_part = ""; $search_words = array(); @@ -711,6 +727,45 @@ $start_ts_query_part = ""; } + + // if previous topmost article id changed that means our current pagination is no longer valid + if ($check_top_id) { + $query = "SELECT DISTINCT + date_entered, + guid, + ttrss_entries.id, + ttrss_entries.title, + updated, + score + FROM + $from_qpart + WHERE + $feed_check_qpart + ttrss_user_entries.ref_id = ttrss_entries.id AND + ttrss_user_entries.owner_uid = '$owner_uid' AND + $search_query_part + $start_ts_query_part + $filter_query_part + $view_query_part + $since_id_part + $query_strategy_part ORDER BY $order_by LIMIT 1"; + + if ($_REQUEST["debug"]) { + print $query; + } + + $result = db_query($query); + if ($result) { + $current_top_id = db_fetch_result($result, 0, "id"); + + if ($current_top_id != $check_top_id) { + // top changed, bail out + + return array(false, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words); + } + } + } + $query = "SELECT DISTINCT date_entered, guid, diff --git a/js/feedlist.js b/js/feedlist.js index 7c2e0805..ffcecc7c 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -99,6 +99,10 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req, can_w query = query + "&m=" + param_escape(method); } + if (current_top_article_id && offset > 0) { + query = query + "&topid=" + param_escape(current_top_article_id); + } + if (!background) { if (_search_query) { force_nocache = true; diff --git a/js/viewfeed.js b/js/viewfeed.js index e346b296..8bc42aad 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -13,6 +13,7 @@ var catchup_timeout_id = false; var cids_requested = []; var loaded_article_ids = []; var _last_headlines_update = 0; +var current_top_article_id = false; var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null; @@ -83,6 +84,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { if (infscroll_req == false) { loaded_article_ids = []; + current_top_article_id = false; dijit.byId("headlines-frame").attr('content', reply['headlines']['content']); @@ -102,6 +104,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } }); + if (loaded_article_ids.size() > 0) { + current_top_article_id = parseInt(loaded_article_ids[0].replace("RROW-", "")); + } + var hsp = $("headlines-spacer"); if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); dijit.byId('headlines-frame').domNode.appendChild(hsp); diff --git a/plugins/vf_shared/init.php b/plugins/vf_shared/init.php index c7eac965..3138c8a7 100644 --- a/plugins/vf_shared/init.php +++ b/plugins/vf_shared/init.php @@ -35,7 +35,7 @@ class VF_Shared extends Plugin { //function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false) { function get_headlines($feed_id, $options) { - $qfh_ret = queryFeedHeadlines(-4, + /*$qfh_ret = queryFeedHeadlines(-4, $options['limit'], $this->get_unread(-1) > 0 ? "adaptive" : "all_articles", false, @@ -49,8 +49,23 @@ class VF_Shared extends Plugin { $options['include_children'], false, "uuid != ''", - "ttrss_feeds.title AS feed_title,"); + "ttrss_feeds.title AS feed_title,"); */ + $params = array( + "feed" => -4, + "limit" => $options["limit"], + "view_mode" => $this->get_unread(-1) > 0 ? "adaptive" : "all_articles", + "search" => $options['search'], + "override_order" => $options['override_order'], + "offset" => $options["offset"], + "filter" => $options["filter"], + "since_id" => $options["since_id"], + "include_children" => $options["include_children"], + "override_strategy" => "uuid != ''", + "override_vfeed" => "ttrss_feeds.title AS feed_title," + ); + + $qfh_ret = queryFeedHeadlines($params); $qfh_ret[1] = __("Shared articles"); return $qfh_ret;