forked from cory/tildefriends
Fast path for viewing a single user's feed, and reduce churn in collecting votes.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3741 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
700d09c730
commit
bb81fc87b9
@ -1 +1 @@
|
|||||||
{"type":"tildefriends-app","files":{"app.js":"&SJrK87ZgHkxZQDB1nm/Xej/bzajzWpiY9a384zqZVzE=.sha256","index.html":"&O8+Vr4YHP8NIORZzM3Ee9tyLXr2xCETT2Eva0rO5ebA=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&ox9wj2+P3BhqokfHPI3ZMpSYNpNhl91K5R6Z4GbWxCA=.sha256","tf.js":"&rUCI1QKOoyWcFegV72DfG/P7HykmkX4DcvWV87hCeBM=.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":"&F1q+r6zHWzbJE9t2rjrhupV2xCIFyJNabXkbGWjHTQQ=.sha256","index.html":"&O8+Vr4YHP8NIORZzM3Ee9tyLXr2xCETT2Eva0rO5ebA=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&ox9wj2+P3BhqokfHPI3ZMpSYNpNhl91K5R6Z4GbWxCA=.sha256","tf.js":"&rUCI1QKOoyWcFegV72DfG/P7HykmkX4DcvWV87hCeBM=.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"}}
|
@ -134,7 +134,32 @@ function fnv32a(value)
|
|||||||
return result >>> 0;
|
return result >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getRecentPostsSingleId(db, id, limit) {
|
||||||
|
var recent = [];
|
||||||
|
await ssb.sqlStream(
|
||||||
|
"SELECT "+
|
||||||
|
" rowid, "+
|
||||||
|
" id, "+
|
||||||
|
" timestamp "+
|
||||||
|
"FROM messages "+
|
||||||
|
"WHERE "+
|
||||||
|
" author = ? AND "+
|
||||||
|
" json_extract(content, '$.type') = 'post' "+
|
||||||
|
"ORDER BY sequence DESC LIMIT ?",
|
||||||
|
[id, limit],
|
||||||
|
function(row) {
|
||||||
|
if (row.id) {
|
||||||
|
recent.push({id: row.id, timestamp: row.timestamp});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
recent.sort((x, y) => y.timestamp - x.timestamp);
|
||||||
|
return recent.map(x => x.id);
|
||||||
|
}
|
||||||
|
|
||||||
async function getRecentPostIds(db, id, ids, limit) {
|
async function getRecentPostIds(db, id, ids, limit) {
|
||||||
|
if (ids.length == 1) {
|
||||||
|
return await getRecentPostsSingleId(db, ids[0], limit);
|
||||||
|
}
|
||||||
const k_version = 11;
|
const k_version = 11;
|
||||||
const k_batch_max = 16;
|
const k_batch_max = 16;
|
||||||
var o = await db.get(id + ':recent_posts');
|
var o = await db.get(id + ':recent_posts');
|
||||||
@ -192,15 +217,14 @@ async function getRecentPostIds(db, id, ids, limit) {
|
|||||||
|
|
||||||
async function getVotes(db, id) {
|
async function getVotes(db, id) {
|
||||||
var o = await db.get(id + ":votes");
|
var o = await db.get(id + ":votes");
|
||||||
const k_version = 5;
|
const k_version = 7;
|
||||||
var votes = [];
|
var votes = [];
|
||||||
var f = o ? JSON.parse(o) : o;
|
var f = o ? JSON.parse(o) : o;
|
||||||
if (!f || f.version != k_version) {
|
if (!f || f.version != k_version) {
|
||||||
f = {votes: [], rowid: 0, version: k_version};
|
f = {votes: [], sequence: 0, version: k_version};
|
||||||
}
|
}
|
||||||
await ssb.sqlStream(
|
await ssb.sqlStream(
|
||||||
"SELECT "+
|
"SELECT "+
|
||||||
" rowid, "+
|
|
||||||
" author, "+
|
" author, "+
|
||||||
" id, "+
|
" id, "+
|
||||||
" sequence, "+
|
" sequence, "+
|
||||||
@ -208,20 +232,19 @@ async function getVotes(db, id) {
|
|||||||
" content "+
|
" content "+
|
||||||
"FROM messages "+
|
"FROM messages "+
|
||||||
"WHERE "+
|
"WHERE "+
|
||||||
" rowid > ? AND "+
|
|
||||||
" author = ? AND "+
|
" author = ? AND "+
|
||||||
|
" sequence > ? AND "+
|
||||||
" json_extract(content, '$.type') = 'vote' "+
|
" json_extract(content, '$.type') = 'vote' "+
|
||||||
"UNION SELECT MAX(rowid) as rowid, NULL, NULL AS id, NULL, NULL, NULL FROM messages "+
|
"UNION SELECT NULL, NULL, MAX(sequence), NULL, NULL FROM messages WHERE author = ? "+
|
||||||
"ORDER BY rowid DESC LIMIT ?",
|
"ORDER BY sequence DESC LIMIT ?",
|
||||||
[f.rowid, id, k_votes_max],
|
[f.sequence, id, id, k_votes_max],
|
||||||
function(row) {
|
function(row) {
|
||||||
if (row.id) {
|
if (row.id) {
|
||||||
votes.push(row);
|
votes.push(row);
|
||||||
} else {
|
|
||||||
f.rowid = row.rowid;
|
|
||||||
}
|
}
|
||||||
|
f.sequence = Math.max(f.sequence, row.sequence);
|
||||||
});
|
});
|
||||||
f.votes = [].concat(votes.reverse(), f.votes).slice(0, k_votes_max);
|
f.votes = [].concat(votes, f.votes).slice(0, k_votes_max);
|
||||||
var j = JSON.stringify(f);
|
var j = JSON.stringify(f);
|
||||||
if (o != j) {
|
if (o != j) {
|
||||||
await db.set(id + ":votes", j);
|
await db.set(id + ":votes", j);
|
||||||
|
Loading…
Reference in New Issue
Block a user