only request counters once for headline mutations

This commit is contained in:
Andrew Dolgov 2021-02-24 10:31:03 +03:00
parent e468e5a589
commit 9ad5f04e51
1 changed files with 25 additions and 12 deletions

View File

@ -149,38 +149,51 @@ const Headlines = {
const promises = [];
if (ops.tmark.length != 0)
promises.push(xhr.json("backend.php",
promises.push(xhr.post("backend.php",
{op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2}));
if (ops.tpub.length != 0)
promises.push(xhr.json("backend.php",
promises.push(xhr.post("backend.php",
{op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2}));
if (ops.read.length != 0)
promises.push(xhr.json("backend.php",
promises.push(xhr.post("backend.php",
{op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0}));
if (ops.unread.length != 0)
promises.push(xhr.json("backend.php",
promises.push(xhr.post("backend.php",
{op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
const scores = Object.keys(ops.rescore);
if (scores.length != 0) {
scores.forEach((score) => {
promises.push(xhr.json("backend.php",
promises.push(xhr.post("backend.php",
{op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score}));
});
}
/*if (promises.length > 0)
Promise.all([promises]).then(() => {
window.clearTimeout(this._observer_counters_timeout);
Promise.all(promises).then((results) => {
let feeds = [];
this._observer_counters_timeout = setTimeout(() => {
Feeds.requestCounters();
}, 1000);
});*/
results.forEach((res) => {
if (res) {
try {
const obj = JSON.parse(res);
if (obj.feeds)
feeds = feeds.concat(obj.feeds);
} catch (e) {
console.warn(e, res);
}
}
});
if (feeds.length > 0)
console.log('requesting counters for', feeds);
Feeds.requestCounters(feeds);
}
);
},
click: function (event, id, in_body) {