From 0cab3e7ed9e25fe76a9b1b95f8a902737385b9ce Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 29 Dec 2021 21:20:24 +0000 Subject: [PATCH] Fixing getRecentPostIds for the millionth time. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3721 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/index.json | 2 +- apps/cory/index/app.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/cory/index.json b/apps/cory/index.json index c34c742e..40411dd5 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -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"}} \ No newline at end of file +{"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"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index 2f7dcc78..f0fe138e 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -150,7 +150,7 @@ function fnv32a(value) } async function getRecentPostIds(db, id, ids, limit) { - const k_version = 9; + const k_version = 10; const k_batch_max = 8; var o = await db.get(id + ':recent_posts'); var recent = []; @@ -161,7 +161,7 @@ async function getRecentPostIds(db, id, ids, limit) { } var row_id_max = 0; await ssb.sqlStream( - "SELECT MAX(rowid) as rowid FROM messages ORDER BY timestamp DESC LIMIT ?", + "SELECT MAX(rowid) as rowid FROM messages", [], function(row) { 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]), function(row) { if (row.id) { - recent.push(row.id); + recent.push({id: row.id, timestamp: row.timestamp}); } if (row.rowid) { f.rowid = Math.max(row.rowid, f.rowid); } }); } - f.recent.sort((x, y) => x.timestamp - y.timestamp); - f.recent = [].concat(recent, f.recent).slice(0, limit); + f.recent = [].concat(recent, f.recent); + f.recent.sort((x, y) => y.timestamp - x.timestamp); + f.recent = f.recent.slice(0, limit); var j = JSON.stringify(f); if (o != j) { await db.set(id + ":recent_posts", j); } - return f.recent; + return f.recent.map(x => x.id); } async function getVotes(db, id) {