forked from cory/tildefriends
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:
@ -42,11 +42,13 @@ async function following(db, id) {
|
||||
}
|
||||
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);
|
||||
if (o != j) {
|
||||
await db.set(id + ":following", j);
|
||||
}
|
||||
f.users = as_set;
|
||||
g_following_cache[id] = f.users;
|
||||
return f.users;
|
||||
}
|
||||
@ -59,7 +61,7 @@ async function followingDeep(db, seed_ids, depth) {
|
||||
if (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 x = await followingDeep(db, [...new Set(ids)].sort(), depth - 1);
|
||||
x = [...new Set([].concat(...x, ...seed_ids))].sort();
|
||||
@ -67,19 +69,11 @@ async function followingDeep(db, seed_ids, depth) {
|
||||
return x;
|
||||
}
|
||||
|
||||
async function followers(db, id) {
|
||||
async function followers(db, visible_users, id) {
|
||||
if (g_followers_cache[id]) {
|
||||
return g_followers_cache[id];
|
||||
}
|
||||
var results = [];
|
||||
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);
|
||||
}
|
||||
}
|
||||
var results = visible_users.filter(user => g_following_cache[user].has(id));
|
||||
g_followers_cache[id] = results;
|
||||
return results;
|
||||
}
|
||||
@ -296,29 +290,24 @@ async function refresh(selected) {
|
||||
ssb.getBroadcasts().then(broadcasts => app.postMessage({broadcasts: broadcasts})),
|
||||
ssb.connections().then(connections => app.postMessage({connections: connections})),
|
||||
core.apps().then(apps => app.postMessage({apps: apps})),
|
||||
getRecentPostIds(db, whoami, g_selected, k_posts_max).then(async function(ids) {
|
||||
var posts = await getPosts(db, ids);
|
||||
var roots = posts.map(function(x) {
|
||||
try {
|
||||
return JSON.parse(x.content).root;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
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));
|
||||
return Promise.all(all_posts.map(x => app.postMessage({message: x})));
|
||||
}),
|
||||
Promise.all([].concat(all_followed.map(function(id) {
|
||||
return [
|
||||
getVotes(db, id).then(votes => app.postMessage({votes: votes})),
|
||||
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}})),
|
||||
];
|
||||
}))),
|
||||
]);
|
||||
var ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
|
||||
var posts = await getPosts(db, ids);
|
||||
var roots = posts.map(function(x) {
|
||||
try {
|
||||
return JSON.parse(x.content).root;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
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));
|
||||
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}}))));
|
||||
await Promise.all(all_followed.map(id => getVotes(db, id).then(results => app.postMessage({votes: results}))));
|
||||
await Promise.all(all_followed.map(id => following(db, id).then(results => app.postMessage({following: {id: id, users: [...results]}}))));
|
||||
await Promise.all(all_followed.map(id => followers(db, all_followed, id).then(results => app.postMessage({followers: {id: id, users: results}}))));
|
||||
await app.postMessage({ready: true});
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
</md-app-toolbar>
|
||||
<md-app-content>
|
||||
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-header>
|
||||
<div class="md-title">What's up?</div>
|
||||
|
@ -19,8 +19,10 @@ var g_data = {
|
||||
selected: null,
|
||||
edit_profile_name: 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_message_queue = [];
|
||||
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});
|
||||
});
|
||||
} else if (key == 'clear') {
|
||||
g_load_start = new Date();
|
||||
g_data.loading = true;
|
||||
Object.keys(g_data_initial).forEach(function(key) {
|
||||
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
|
||||
});
|
||||
} else if (key == 'ready') {
|
||||
g_data.load_time = (new Date() - g_load_start) / 1000;
|
||||
g_data.loading = false;
|
||||
} else if (key == 'unread') {
|
||||
g_data.unread += event.data.unread;
|
||||
|
Reference in New Issue
Block a user