Show a breakdown of timing.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3797 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-27 01:17:22 +00:00
parent 9fd4be0e4a
commit e4d77679dc
4 changed files with 30 additions and 3 deletions

View File

@@ -305,13 +305,17 @@ core.register('onConnectionsChanged', async function() {
});
async function refresh(selected) {
var timing = [];
timing.push({name: 'start', time: new Date()});
g_following_cache = {};
g_followers_cache = {};
g_following_deep_cache = {};
await app.postMessage({clear: true});
var whoami = await ssb.whoami();
var db = await database("ssb");
timing.push({name: 'init', time: new Date()});
var all_followed = await followingDeep(db, [whoami], 2);
timing.push({name: 'all_followed', time: new Date()});
if (selected) {
g_selected = selected;
} else {
@@ -324,6 +328,7 @@ async function refresh(selected) {
ssb.connections().then(connections => app.postMessage({connections: connections})),
core.apps().then(apps => app.postMessage({apps: apps})),
]);
timing.push({name: 'core', time: new Date()});
var ids;
if (selected && selected.length == 1 && selected[0].startsWith('%')) {
var m = await getPosts(db, selected);
@@ -332,7 +337,9 @@ async function refresh(selected) {
} else {
ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
}
timing.push({name: 'get_post_ids', time: new Date()});
var posts = await getPosts(db, ids);
timing.push({name: 'get_posts', time: new Date()});
var roots = posts.map(function(x) {
try {
return JSON.parse(x.content).root;
@@ -343,11 +350,24 @@ async function refresh(selected) {
var have = new Set(posts.map(x => x.id));
roots = [...new Set(roots)].filter(x => x && !have.has(x));
var all_posts = [].concat(posts, await getPosts(db, roots));
timing.push({name: 'get_root_posts', time: new Date()});
await Promise.all(all_posts.map(x => app.postMessage({message: x})));
timing.push({name: 'send_posts', time: new Date()});
await Promise.all(all_followed.map(id => getAbout(db, id).then(results => app.postMessage({user: {user: id, about: results}}))));
timing.push({name: 'about', time: new Date()});
await Promise.all(all_followed.map(id => getVotes(db, id).then(results => results.length ? app.postMessage({votes: results}) : null)));
timing.push({name: 'votes', time: new Date()});
await Promise.all(all_followed.map(id => following(db, id).then(results => app.postMessage({following: {id: id, users: [...results]}}))));
await app.postMessage({ready: true});
timing.push({name: 'following', time: new Date()});
var times = {};
var previous = null;
for (let t of timing) {
times[t.name] = t.time - (previous || t).time;
previous = t;
}
await app.postMessage({ready: true, times: times});
}
ssb.addEventListener('message', async function(id) {