Fixing getRecentPostIds for the millionth time.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3721 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2021-12-29 21:20:24 +00:00
parent 12010a84a3
commit 0cab3e7ed9
2 changed files with 8 additions and 7 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&jkL7crcAyW2KFUlHb43k+cY6JN9Ee3F0gy6ba4p70kg=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&taC9THJslxAMy72UIplFjALJx1VHv2l+qfjWoRhhrS4=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&u6n7Eqa1ryFuL9AhlYeJ/WzXYh6zxECKVfhG8/ecRM8=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}} {"type":"tildefriends-app","files":{"app.js":"&bKoyBQBiMZinCQUoQIqGpeehKgqkANw8Ns2OYECYW30=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&taC9THJslxAMy72UIplFjALJx1VHv2l+qfjWoRhhrS4=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&u6n7Eqa1ryFuL9AhlYeJ/WzXYh6zxECKVfhG8/ecRM8=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}}

View File

@ -150,7 +150,7 @@ function fnv32a(value)
} }
async function getRecentPostIds(db, id, ids, limit) { async function getRecentPostIds(db, id, ids, limit) {
const k_version = 9; const k_version = 10;
const k_batch_max = 8; const k_batch_max = 8;
var o = await db.get(id + ':recent_posts'); var o = await db.get(id + ':recent_posts');
var recent = []; var recent = [];
@ -161,7 +161,7 @@ async function getRecentPostIds(db, id, ids, limit) {
} }
var row_id_max = 0; var row_id_max = 0;
await ssb.sqlStream( await ssb.sqlStream(
"SELECT MAX(rowid) as rowid FROM messages ORDER BY timestamp DESC LIMIT ?", "SELECT MAX(rowid) as rowid FROM messages",
[], [],
function(row) { function(row) {
row_id_max = row.rowid; row_id_max = row.rowid;
@ -183,20 +183,21 @@ async function getRecentPostIds(db, id, ids, limit) {
[].concat([f.rowid, row_id_max], ids_batch, [limit]), [].concat([f.rowid, row_id_max], ids_batch, [limit]),
function(row) { function(row) {
if (row.id) { if (row.id) {
recent.push(row.id); recent.push({id: row.id, timestamp: row.timestamp});
} }
if (row.rowid) { if (row.rowid) {
f.rowid = Math.max(row.rowid, f.rowid); f.rowid = Math.max(row.rowid, f.rowid);
} }
}); });
} }
f.recent.sort((x, y) => x.timestamp - y.timestamp); f.recent = [].concat(recent, f.recent);
f.recent = [].concat(recent, f.recent).slice(0, limit); f.recent.sort((x, y) => y.timestamp - x.timestamp);
f.recent = f.recent.slice(0, limit);
var j = JSON.stringify(f); var j = JSON.stringify(f);
if (o != j) { if (o != j) {
await db.set(id + ":recent_posts", j); await db.set(id + ":recent_posts", j);
} }
return f.recent; return f.recent.map(x => x.id);
} }
async function getVotes(db, id) { async function getVotes(db, id) {