From f5a0fb8b64c57e98fcf73369cb4dbb1b31620fd7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 01:29:36 +0300 Subject: queryFeedHeadlines: move to array-based arguments, optionally check if first element changed when paginating --- include/functions2.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 133352f75..e4e66acd1 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, -- cgit v1.2.3 From 34440201006344012ed01e37f883f2f0c11fcba7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 12:01:34 +0300 Subject: report top id changed in headlines buffer --- include/functions2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index e4e66acd1..31504a38b 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -761,7 +761,7 @@ 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); + return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words); } } } -- cgit v1.2.3 From 83ce77a2e8fbffc4c179f190dbc5d97f459a01f7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 14:07:38 +0300 Subject: functions: fix some phpstorm-reported warnings --- include/functions2.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 31504a38b..282571850 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -447,6 +447,8 @@ $check_top_id = isset($params["check_top_id"]) ? $params["check_top_id"] : false; $ext_tables_part = ""; + $query_strategy_part = ""; + $search_words = array(); if ($search) { @@ -1194,7 +1196,7 @@ $_SESSION["hasMp3"])) { $entry .= ""; } else { @@ -1619,6 +1621,7 @@ return __("no tags"); } else { $maxtags = min(5, count($tags)); + $tags_str = ""; for ($i = 0; $i < $maxtags; $i++) { $tags_str .= "" . $tags[$i] . ", "; -- cgit v1.2.3 From 48fefe2f6b6e625b64b0c6d54e35e3608e70a1bd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 17:55:35 +0300 Subject: fixes for first_id stuff --- include/functions2.php | 53 +++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 282571850..a85c49ccf 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -444,7 +444,7 @@ $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; + $check_first_id = isset($params["check_first_id"]) ? $params["check_first_id"] : false; $ext_tables_part = ""; $query_strategy_part = ""; @@ -729,28 +729,26 @@ $start_ts_query_part = ""; } - + $first_id = false; // 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"; + $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 + $since_id_part + $query_strategy_part ORDER BY $order_by LIMIT 1"; if ($_REQUEST["debug"]) { print $query; @@ -758,15 +756,12 @@ $result = db_query($query); if ($result) { - $current_top_id = db_fetch_result($result, 0, "id"); + $first_id = (int) db_fetch_result($result, 0, "id"); - if ($current_top_id != $check_top_id) { - // top changed, bail out - - return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words); + if ($offset > 0 && $check_first_id && $first_id != $check_first_id) { + return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id); } } - } $query = "SELECT DISTINCT date_entered, @@ -851,7 +846,7 @@ $result = db_query($query); } - return array($result, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words); + return array($result, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id); } -- cgit v1.2.3 From d5e0486e0cd10503df3f249e8c12760d960e5b63 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 18:47:06 +0300 Subject: minor first_id query fix --- include/functions2.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index a85c49ccf..141c6d1cd 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -732,6 +732,7 @@ $first_id = false; // if previous topmost article id changed that means our current pagination is no longer valid $query = "SELECT DISTINCT + ttrss_feeds.title, date_entered, guid, ttrss_entries.id, -- cgit v1.2.3 From 8831632905398e5cfe2c3d071a5feaf8ac05d48b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 22:50:21 +0300 Subject: add some more stuff to first_id query to fix virtual feeds --- include/functions2.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 141c6d1cd..11274b713 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -738,7 +738,11 @@ ttrss_entries.id, ttrss_entries.title, updated, - score + score, + marked, + published, + last_marked, + last_published FROM $from_qpart WHERE -- cgit v1.2.3 From f7fd1edb76fcb3b56ef4d327f8851484e782a1f8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 12 Jul 2015 22:54:55 +0300 Subject: first_id default value: type is important --- include/functions2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 11274b713..459a2a533 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -729,7 +729,7 @@ $start_ts_query_part = ""; } - $first_id = false; + $first_id = 0; // if previous topmost article id changed that means our current pagination is no longer valid $query = "SELECT DISTINCT ttrss_feeds.title, @@ -760,10 +760,10 @@ } $result = db_query($query); - if ($result) { + if ($result && db_num_rows($result) > 0) { $first_id = (int) db_fetch_result($result, 0, "id"); - if ($offset > 0 && $check_first_id && $first_id != $check_first_id) { + if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) { return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id); } } -- cgit v1.2.3 From f56e5a35041878b5ec827e96ce3ac78a0df944c8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Jul 2015 00:40:15 +0300 Subject: add workaround for fresh feed first id calculation issue --- include/functions2.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index 459a2a533..e0b9e24ad 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -730,6 +730,11 @@ } $first_id = 0; + $first_id_query_strategy_part = $query_strategy_part; + + if ($feed == -3) + $first_id_query_strategy_part = "true"; + // if previous topmost article id changed that means our current pagination is no longer valid $query = "SELECT DISTINCT ttrss_feeds.title, @@ -753,7 +758,7 @@ $start_ts_query_part $filter_query_part $since_id_part - $query_strategy_part ORDER BY $order_by LIMIT 1"; + $first_id_query_strategy_part ORDER BY $order_by LIMIT 1"; if ($_REQUEST["debug"]) { print $query; -- cgit v1.2.3 From 0e4da73f06a2d30ecd02b185d21671ed44737631 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Jul 2015 01:22:44 +0300 Subject: do not allow commas in tags --- include/functions2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/functions2.php') diff --git a/include/functions2.php b/include/functions2.php index e0b9e24ad..2c3133883 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -1483,7 +1483,7 @@ $tag = mb_strtolower($tag, 'utf-8'); - $tag = preg_replace('/[\'\"\+\>\<]/', "", $tag); + $tag = preg_replace('/[,\'\"\+\>\<]/', "", $tag); if (DB_TYPE == "mysql") { $tag = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $tag); -- cgit v1.2.3