try to calculate counters conditionally based on feed ids
This commit is contained in:
parent
a42e8aad97
commit
d6203bf350
|
@ -640,4 +640,20 @@ class Article extends Handler_Protected {
|
||||||
return [$article_image, $article_stream, $article_kind];
|
return [$article_image, $article_stream, $article_kind];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function _feeds_of(array $article_ids) {
|
||||||
|
$id_qmarks = arr_qmarks($article_ids);
|
||||||
|
|
||||||
|
$sth = DB::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue
|
||||||
|
WHERE ue.ref_id = e.id AND id IN ($id_qmarks)");
|
||||||
|
|
||||||
|
$sth->execute($article_ids);
|
||||||
|
|
||||||
|
$rv = [];
|
||||||
|
|
||||||
|
while ($row = $sth->fetch()) {
|
||||||
|
array_push($rv, $row["feed_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,15 @@ class Counters {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function get_for_feeds($feed_ids) {
|
||||||
|
return array_merge(
|
||||||
|
self::get_global(),
|
||||||
|
self::get_virt(),
|
||||||
|
self::get_labels(),
|
||||||
|
self::get_feeds($feed_ids),
|
||||||
|
self::get_cats(Feeds::_cats_of($feed_ids, $_SESSION["uid"], true)));
|
||||||
|
}
|
||||||
|
|
||||||
static private function get_cat_children($cat_id, $owner_uid) {
|
static private function get_cat_children($cat_id, $owner_uid) {
|
||||||
$pdo = Db::pdo();
|
$pdo = Db::pdo();
|
||||||
|
|
||||||
|
@ -31,7 +40,7 @@ class Counters {
|
||||||
return [$unread, $marked];
|
return [$unread, $marked];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function get_cats() {
|
private static function get_cats(array $cat_ids = []) {
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
/* Labels category */
|
/* Labels category */
|
||||||
|
@ -43,27 +52,57 @@ class Counters {
|
||||||
|
|
||||||
$pdo = Db::pdo();
|
$pdo = Db::pdo();
|
||||||
|
|
||||||
$sth = $pdo->prepare("SELECT fc.id,
|
if (count($cat_ids) == 0) {
|
||||||
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
$sth = $pdo->prepare("SELECT fc.id,
|
||||||
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
(SELECT COUNT(id) FROM ttrss_feed_categories fcc
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
||||||
WHERE fcc.parent_cat = fc.id) AS num_children
|
(SELECT COUNT(id) FROM ttrss_feed_categories fcc
|
||||||
FROM ttrss_feed_categories fc
|
WHERE fcc.parent_cat = fc.id) AS num_children
|
||||||
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
FROM ttrss_feed_categories fc
|
||||||
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
||||||
WHERE fc.owner_uid = :uid
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
||||||
GROUP BY fc.id
|
WHERE fc.owner_uid = :uid
|
||||||
UNION
|
GROUP BY fc.id
|
||||||
SELECT 0,
|
UNION
|
||||||
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
SELECT 0,
|
||||||
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
0
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
||||||
FROM ttrss_feeds f, ttrss_user_entries ue
|
0
|
||||||
WHERE f.cat_id IS NULL AND
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
||||||
ue.feed_id = f.id AND
|
WHERE f.cat_id IS NULL AND
|
||||||
ue.owner_uid = :uid");
|
ue.feed_id = f.id AND
|
||||||
|
ue.owner_uid = :uid");
|
||||||
|
|
||||||
$sth->execute(["uid" => $_SESSION['uid']]);
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
||||||
|
} else {
|
||||||
|
$cat_ids_qmarks = arr_qmarks($cat_ids);
|
||||||
|
|
||||||
|
$sth = $pdo->prepare("SELECT fc.id,
|
||||||
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
||||||
|
(SELECT COUNT(id) FROM ttrss_feed_categories fcc
|
||||||
|
WHERE fcc.parent_cat = fc.id) AS num_children
|
||||||
|
FROM ttrss_feed_categories fc
|
||||||
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
||||||
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
||||||
|
WHERE fc.owner_uid = ? AND fc.id IN ($cat_ids_qmarks)
|
||||||
|
GROUP BY fc.id
|
||||||
|
UNION
|
||||||
|
SELECT 0,
|
||||||
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
||||||
|
0
|
||||||
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
||||||
|
WHERE f.cat_id IS NULL AND
|
||||||
|
ue.feed_id = f.id AND
|
||||||
|
ue.owner_uid = ?");
|
||||||
|
|
||||||
|
$sth->execute(array_merge(
|
||||||
|
[$_SESSION['uid']],
|
||||||
|
$cat_ids,
|
||||||
|
[$_SESSION['uid']]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
while ($line = $sth->fetch()) {
|
while ($line = $sth->fetch()) {
|
||||||
if ($line["num_children"] > 0) {
|
if ($line["num_children"] > 0) {
|
||||||
|
@ -83,29 +122,42 @@ class Counters {
|
||||||
array_push($ret, $cv);
|
array_push($ret, $cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($ret, $cv);
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function get_feeds(array $feed_ids = []) {
|
||||||
private static function get_feeds($active_feed = false) {
|
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
$pdo = Db::pdo();
|
$pdo = Db::pdo();
|
||||||
|
|
||||||
$sth = $pdo->prepare("SELECT f.id,
|
if (count($feed_ids) == 0) {
|
||||||
f.title,
|
$sth = $pdo->prepare("SELECT f.id,
|
||||||
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
f.title,
|
||||||
f.last_error,
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
||||||
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
f.last_error,
|
||||||
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
FROM ttrss_feeds f, ttrss_user_entries ue
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
||||||
WHERE f.id = ue.feed_id AND ue.owner_uid = :uid
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
||||||
GROUP BY f.id");
|
WHERE f.id = ue.feed_id AND ue.owner_uid = :uid
|
||||||
|
GROUP BY f.id");
|
||||||
|
|
||||||
$sth->execute(["uid" => $_SESSION['uid']]);
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
||||||
|
} else {
|
||||||
|
$feed_ids_qmarks = arr_qmarks($feed_ids);
|
||||||
|
|
||||||
|
$sth = $pdo->prepare("SELECT f.id,
|
||||||
|
f.title,
|
||||||
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
||||||
|
f.last_error,
|
||||||
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
||||||
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
||||||
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
||||||
|
WHERE f.id = ue.feed_id AND ue.owner_uid = ? AND f.id IN ($feed_ids_qmarks)
|
||||||
|
GROUP BY f.id");
|
||||||
|
|
||||||
|
$sth->execute(array_merge([$_SESSION['uid']], $feed_ids));
|
||||||
|
}
|
||||||
|
|
||||||
while ($line = $sth->fetch()) {
|
while ($line = $sth->fetch()) {
|
||||||
|
|
||||||
|
|
|
@ -1765,7 +1765,7 @@ class Feeds extends Handler_Protected {
|
||||||
$sth->execute([$cat, $owner_uid]);
|
$sth->execute([$cat, $owner_uid]);
|
||||||
|
|
||||||
while ($line = $sth->fetch()) {
|
while ($line = $sth->fetch()) {
|
||||||
array_push($rv, $line["parent_cat"]);
|
array_push($rv, (int)$line["parent_cat"]);
|
||||||
$rv = array_merge($rv, self::_get_parent_cats($line["parent_cat"], $owner_uid));
|
$rv = array_merge($rv, self::_get_parent_cats($line["parent_cat"], $owner_uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1789,6 +1789,30 @@ class Feeds extends Handler_Protected {
|
||||||
return $rv;
|
return $rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function _cats_of(array $feeds, int $owner_uid, bool $with_parents = false) {
|
||||||
|
$pdo = Db::pdo();
|
||||||
|
|
||||||
|
$feeds_qmarks = arr_qmarks($feeds);
|
||||||
|
|
||||||
|
$sth = $pdo->prepare("SELECT DISTINCT cat_id FROM ttrss_feeds
|
||||||
|
WHERE id IN ($feeds_qmarks)");
|
||||||
|
$sth->execute($feeds);
|
||||||
|
|
||||||
|
$rv = [];
|
||||||
|
|
||||||
|
if ($row = $sth->fetch()) {
|
||||||
|
array_push($rv, (int)$row["cat_id"]);
|
||||||
|
|
||||||
|
if ($with_parents)
|
||||||
|
$rv = array_merge($rv,
|
||||||
|
self::_get_parent_cats($row["cat_id"], $owner_uid));
|
||||||
|
}
|
||||||
|
|
||||||
|
$rv = array_unique($rv);
|
||||||
|
|
||||||
|
return $rv;
|
||||||
|
}
|
||||||
|
|
||||||
static function _cat_of_feed($feed) {
|
static function _cat_of_feed($feed) {
|
||||||
$pdo = Db::pdo();
|
$pdo = Db::pdo();
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,21 @@ class RPC extends Handler_Protected {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllCounters() {
|
function getAllCounters() {
|
||||||
|
$feed_ids = array_map("intval",
|
||||||
|
explode(",",
|
||||||
|
clean($_REQUEST["feed_ids"])));
|
||||||
|
|
||||||
@$seq = (int) $_REQUEST['seq'];
|
@$seq = (int) $_REQUEST['seq'];
|
||||||
|
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
|
$counters = count($feed_ids) > 0 ? Counters::get_for_feeds($feed_ids) : Counters::get_all();
|
||||||
|
|
||||||
$reply = [
|
$reply = [
|
||||||
'counters' => Counters::get_all(),
|
'counters' => $counters,
|
||||||
'seq' => $seq
|
'seq' => $seq
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($seq % 2 == 0)
|
if ($seq % 2)
|
||||||
$reply['runtime-info'] = $this->make_runtime_info();
|
$reply['runtime-info'] = $this->make_runtime_info();
|
||||||
|
|
||||||
print json_encode($reply);
|
print json_encode($reply);
|
||||||
|
@ -88,30 +95,39 @@ class RPC extends Handler_Protected {
|
||||||
|
|
||||||
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
|
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
|
||||||
function catchupSelected() {
|
function catchupSelected() {
|
||||||
$ids = explode(",", clean($_REQUEST["ids"]));
|
$ids = array_map("intval",
|
||||||
|
explode(",",
|
||||||
|
clean($_REQUEST["ids"])));
|
||||||
|
|
||||||
$cmode = (int)clean($_REQUEST["cmode"]);
|
$cmode = (int)clean($_REQUEST["cmode"]);
|
||||||
|
|
||||||
Article::_catchup_by_id($ids, $cmode);
|
Article::_catchup_by_id($ids, $cmode);
|
||||||
|
|
||||||
print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
|
print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function markSelected() {
|
function markSelected() {
|
||||||
$ids = explode(",", clean($_REQUEST["ids"]));
|
$ids = array_map("intval",
|
||||||
|
explode(",",
|
||||||
|
clean($_REQUEST["ids"])));
|
||||||
|
|
||||||
$cmode = (int)clean($_REQUEST["cmode"]);
|
$cmode = (int)clean($_REQUEST["cmode"]);
|
||||||
|
|
||||||
$this->markArticlesById($ids, $cmode);
|
$this->markArticlesById($ids, $cmode);
|
||||||
|
|
||||||
print json_encode(array("message" => "UPDATE_COUNTERS"));
|
print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishSelected() {
|
function publishSelected() {
|
||||||
$ids = explode(",", clean($_REQUEST["ids"]));
|
$ids = array_map("intval",
|
||||||
|
explode(",",
|
||||||
|
clean($_REQUEST["ids"])));
|
||||||
|
|
||||||
$cmode = (int)clean($_REQUEST["cmode"]);
|
$cmode = (int)clean($_REQUEST["cmode"]);
|
||||||
|
|
||||||
$this->publishArticlesById($ids, $cmode);
|
$this->publishArticlesById($ids, $cmode);
|
||||||
|
|
||||||
print json_encode(array("message" => "UPDATE_COUNTERS"));
|
print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanityCheck() {
|
function sanityCheck() {
|
||||||
|
|
|
@ -421,8 +421,8 @@ const App = {
|
||||||
// not in preferences
|
// not in preferences
|
||||||
if (typeof Feeds != "undefined") {
|
if (typeof Feeds != "undefined") {
|
||||||
if (message == "UPDATE_COUNTERS") {
|
if (message == "UPDATE_COUNTERS") {
|
||||||
console.log("need to refresh counters...");
|
console.log("need to refresh counters for", reply.feeds);
|
||||||
Feeds.requestCounters(true);
|
Feeds.requestCounters(reply.feeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counters)
|
if (counters)
|
||||||
|
|
10
js/Feeds.js
10
js/Feeds.js
|
@ -133,8 +133,8 @@ const Feeds = {
|
||||||
this._search_query = "";
|
this._search_query = "";
|
||||||
this.reloadCurrent();
|
this.reloadCurrent();
|
||||||
},
|
},
|
||||||
requestCounters: function() {
|
requestCounters: function(feed_ids = null) {
|
||||||
xhr.json("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, () => {
|
xhr.json("backend.php", {op: "rpc", method: "getAllCounters", feed_ids: feed_ids, seq: App.next_seq()}, () => {
|
||||||
//
|
//
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -264,10 +264,10 @@ const Feeds = {
|
||||||
|
|
||||||
// bw_limit disables timeout() so we request initial counters separately
|
// bw_limit disables timeout() so we request initial counters separately
|
||||||
if (App.getInitParam("bw_limit")) {
|
if (App.getInitParam("bw_limit")) {
|
||||||
this.requestCounters(true);
|
this.requestCounters();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.requestCounters(true);
|
this.requestCounters();
|
||||||
setInterval(() => { this.requestCounters(); }, 60 * 1000)
|
setInterval(() => { this.requestCounters(); }, 60 * 1000)
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ const Feeds = {
|
||||||
Notify.progress("Marking all feeds as read...");
|
Notify.progress("Marking all feeds as read...");
|
||||||
|
|
||||||
xhr.post("backend.php", {op: "feeds", method: "catchupAll"}, () => {
|
xhr.post("backend.php", {op: "feeds", method: "catchupAll"}, () => {
|
||||||
this.requestCounters(true);
|
this.requestCounters();
|
||||||
this.reloadCurrent();
|
this.reloadCurrent();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
const Headlines = {
|
const Headlines = {
|
||||||
vgroup_last_feed: undefined,
|
vgroup_last_feed: undefined,
|
||||||
_headlines_scroll_timeout: 0,
|
_headlines_scroll_timeout: 0,
|
||||||
_observer_counters_timeout: 0,
|
//_observer_counters_timeout: 0,
|
||||||
headlines: [],
|
headlines: [],
|
||||||
current_first_id: 0,
|
current_first_id: 0,
|
||||||
_scroll_reset_timeout: false,
|
_scroll_reset_timeout: false,
|
||||||
|
@ -149,38 +149,38 @@ const Headlines = {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
if (ops.tmark.length != 0)
|
if (ops.tmark.length != 0)
|
||||||
promises.push(xhr.post("backend.php",
|
promises.push(xhr.json("backend.php",
|
||||||
{op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2}));
|
{op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2}));
|
||||||
|
|
||||||
if (ops.tpub.length != 0)
|
if (ops.tpub.length != 0)
|
||||||
promises.push(xhr.post("backend.php",
|
promises.push(xhr.json("backend.php",
|
||||||
{op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2}));
|
{op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2}));
|
||||||
|
|
||||||
if (ops.read.length != 0)
|
if (ops.read.length != 0)
|
||||||
promises.push(xhr.post("backend.php",
|
promises.push(xhr.json("backend.php",
|
||||||
{op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0}));
|
{op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0}));
|
||||||
|
|
||||||
if (ops.unread.length != 0)
|
if (ops.unread.length != 0)
|
||||||
promises.push(xhr.post("backend.php",
|
promises.push(xhr.json("backend.php",
|
||||||
{op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
|
{op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
|
||||||
|
|
||||||
const scores = Object.keys(ops.rescore);
|
const scores = Object.keys(ops.rescore);
|
||||||
|
|
||||||
if (scores.length != 0) {
|
if (scores.length != 0) {
|
||||||
scores.forEach((score) => {
|
scores.forEach((score) => {
|
||||||
promises.push(xhr.post("backend.php",
|
promises.push(xhr.json("backend.php",
|
||||||
{op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score}));
|
{op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promises.length > 0)
|
/*if (promises.length > 0)
|
||||||
Promise.all([promises]).then(() => {
|
Promise.all([promises]).then(() => {
|
||||||
window.clearTimeout(this._observer_counters_timeout);
|
window.clearTimeout(this._observer_counters_timeout);
|
||||||
|
|
||||||
this._observer_counters_timeout = setTimeout(() => {
|
this._observer_counters_timeout = setTimeout(() => {
|
||||||
Feeds.requestCounters(true);
|
Feeds.requestCounters();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});*/
|
||||||
|
|
||||||
},
|
},
|
||||||
click: function (event, id, in_body) {
|
click: function (event, id, in_body) {
|
||||||
|
|
Loading…
Reference in New Issue