Show load time. Make it faster. Make it easier to instrument.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3747 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-09 20:36:15 +00:00
parent c28d4d9378
commit 32c7fcbbfa
4 changed files with 29 additions and 35 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&F1q+r6zHWzbJE9t2rjrhupV2xCIFyJNabXkbGWjHTQQ=.sha256","index.html":"&Wllj8FUH4aUEyb79PJETNY3edqGlY5Mic/4nS9fH9nA=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&eS1jLx23k9mytvuDdxHu/NPblvlmp8HY46uvCP7GtVY=.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":"&XVSFb4Gp/ts/5eRWY+l2vZOeWwokQJd8xO0zoDT2Nrw=.sha256","index.html":"&/CE4CuVKI56h5tfAHF0kzCXbLfhVjWzsM8aZAB9HpEM=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&eS1jLx23k9mytvuDdxHu/NPblvlmp8HY46uvCP7GtVY=.sha256","tf.js":"&k1spHFz1z0DroPr/95QBOjR3RVeCJi61TK4i2Xr37uE=.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

@ -42,11 +42,13 @@ async function following(db, id) {
} }
f.sequence = row.sequence; f.sequence = row.sequence;
}); });
f.users = Array.from(f.users); var as_set = f.users;
f.users = Array.from(f.users).sort();
var j = JSON.stringify(f); var j = JSON.stringify(f);
if (o != j) { if (o != j) {
await db.set(id + ":following", j); await db.set(id + ":following", j);
} }
f.users = as_set;
g_following_cache[id] = f.users; g_following_cache[id] = f.users;
return f.users; return f.users;
} }
@ -59,7 +61,7 @@ async function followingDeep(db, seed_ids, depth) {
if (g_following_deep_cache[key]) { if (g_following_deep_cache[key]) {
return g_following_deep_cache[key]; return g_following_deep_cache[key];
} }
var f = await Promise.all(seed_ids.map(x => following(db, x))); var f = await Promise.all(seed_ids.map(x => following(db, x).then(x => [...x])));
var ids = [].concat(...f); var ids = [].concat(...f);
var x = await followingDeep(db, [...new Set(ids)].sort(), depth - 1); var x = await followingDeep(db, [...new Set(ids)].sort(), depth - 1);
x = [...new Set([].concat(...x, ...seed_ids))].sort(); x = [...new Set([].concat(...x, ...seed_ids))].sort();
@ -67,19 +69,11 @@ async function followingDeep(db, seed_ids, depth) {
return x; return x;
} }
async function followers(db, id) { async function followers(db, visible_users, id) {
if (g_followers_cache[id]) { if (g_followers_cache[id]) {
return g_followers_cache[id]; return g_followers_cache[id];
} }
var results = []; var results = visible_users.filter(user => g_following_cache[user].has(id));
var me = await ssb.whoami();
var visible_users = await followingDeep(db, [me], 2);
for (let user of visible_users) {
var followed = await following(db, user);
if (followed.indexOf(id)) {
results.push(user);
}
}
g_followers_cache[id] = results; g_followers_cache[id] = results;
return results; return results;
} }
@ -296,7 +290,8 @@ async function refresh(selected) {
ssb.getBroadcasts().then(broadcasts => app.postMessage({broadcasts: broadcasts})), ssb.getBroadcasts().then(broadcasts => app.postMessage({broadcasts: broadcasts})),
ssb.connections().then(connections => app.postMessage({connections: connections})), ssb.connections().then(connections => app.postMessage({connections: connections})),
core.apps().then(apps => app.postMessage({apps: apps})), core.apps().then(apps => app.postMessage({apps: apps})),
getRecentPostIds(db, whoami, g_selected, k_posts_max).then(async function(ids) { ]);
var ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
var posts = await getPosts(db, ids); var posts = await getPosts(db, ids);
var roots = posts.map(function(x) { var roots = posts.map(function(x) {
try { try {
@ -308,17 +303,11 @@ async function refresh(selected) {
var have = new Set(posts.map(x => x.id)); var have = new Set(posts.map(x => x.id));
roots = [...new Set(roots)].filter(x => x && !have.has(x)); roots = [...new Set(roots)].filter(x => x && !have.has(x));
var all_posts = [].concat(posts, await getPosts(db, roots)); var all_posts = [].concat(posts, await getPosts(db, roots));
return Promise.all(all_posts.map(x => app.postMessage({message: x}))); await Promise.all(all_posts.map(x => app.postMessage({message: x})));
}), await Promise.all(all_followed.map(id => getAbout(db, id).then(results => app.postMessage({user: {user: id, about: results}}))));
Promise.all([].concat(all_followed.map(function(id) { await Promise.all(all_followed.map(id => getVotes(db, id).then(results => app.postMessage({votes: results}))));
return [ await Promise.all(all_followed.map(id => following(db, id).then(results => app.postMessage({following: {id: id, users: [...results]}}))));
getVotes(db, id).then(votes => app.postMessage({votes: votes})), await Promise.all(all_followed.map(id => followers(db, all_followed, id).then(results => app.postMessage({followers: {id: id, users: results}}))));
getAbout(db, id).then(user => app.postMessage({user: {user: id, about: user}})),
following(db, id).then(f => app.postMessage({following: {id: id, users: f}})),
followers(db, id).then(f => app.postMessage({followers: {id: id, users: f}})),
];
}))),
]);
await app.postMessage({ready: true}); await app.postMessage({ready: true});
} }

View File

@ -46,6 +46,7 @@
</md-app-toolbar> </md-app-toolbar>
<md-app-content> <md-app-content>
Welcome, <tf-user :id="whoami"></tf-user>. Welcome, <tf-user :id="whoami"></tf-user>.
<span v-if="load_time" style="float: right">Loaded in {{load_time}} seconds.</span>
<md-card class="md-elevation-8"> <md-card class="md-elevation-8">
<md-card-header> <md-card-header>
<div class="md-title">What's up?</div> <div class="md-title">What's up?</div>

View File

@ -19,8 +19,10 @@ var g_data = {
selected: null, selected: null,
edit_profile_name: null, edit_profile_name: null,
edit_profile_description: null, edit_profile_description: null,
load_time: null,
}; };
var g_load_start = new Date();
var g_data_initial = JSON.parse(JSON.stringify(g_data)); var g_data_initial = JSON.parse(JSON.stringify(g_data));
var g_message_queue = []; var g_message_queue = [];
var g_process_pending = false; var g_process_pending = false;
@ -106,11 +108,13 @@ function processMessages() {
g_data.votes[link][content.vote.expression].push({author: vote.author, value: content.vote.value}); g_data.votes[link][content.vote.expression].push({author: vote.author, value: content.vote.value});
}); });
} else if (key == 'clear') { } else if (key == 'clear') {
g_load_start = new Date();
g_data.loading = true; g_data.loading = true;
Object.keys(g_data_initial).forEach(function(key) { Object.keys(g_data_initial).forEach(function(key) {
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key]))); Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
}); });
} else if (key == 'ready') { } else if (key == 'ready') {
g_data.load_time = (new Date() - g_load_start) / 1000;
g_data.loading = false; g_data.loading = false;
} else if (key == 'unread') { } else if (key == 'unread') {
g_data.unread += event.data.unread; g_data.unread += event.data.unread;