From ac92b5f8deb1a334b5f0cedfc1c6eb0ebd30df11 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 23 Jan 2022 19:15:18 +0000 Subject: [PATCH] Make the client figure out followers rather than going back to the database. Faster loads. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3790 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/index.json | 2 +- apps/cory/index/app.js | 12 +----------- apps/cory/index/tf.js | 17 +++++++---------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/apps/cory/index.json b/apps/cory/index.json index 0acd1f9c..06beaaeb 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&uXK7Jr1DcwfxabWjUOHVsElPbSyBB35bSrNSElnUlik=.sha256","index.html":"&eY9aBHpnmbMTXXnbzv9gxxXvJp8O5NpcqulQxdnsW/s=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&3dPiSNYjoJE3zn1oTT1SBhbvkW9MHr7ZUDxUJiBI1Ss=.sha256","tf.js":"&qaMkoT5UElfhFNFcDLimlm3asDLaYytsypoz7CJh9q0=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&Vi9pHWY2Dh6+cJlX0lLa4gxrC7VlkeWaU0fQidwzaQ0=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&MctA7OZPTgdTZnlSwKMJTYjZg+S8blg4VdO/njxN0QU=.sha256","index.html":"&eY9aBHpnmbMTXXnbzv9gxxXvJp8O5NpcqulQxdnsW/s=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&3dPiSNYjoJE3zn1oTT1SBhbvkW9MHr7ZUDxUJiBI1Ss=.sha256","tf.js":"&7hS4IikdZdlZDiMlZ1UK9Wf6rdOwceevKGPBRlhDZ68=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&Vi9pHWY2Dh6+cJlX0lLa4gxrC7VlkeWaU0fQidwzaQ0=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index f0daa5c1..c05892a9 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -69,15 +69,6 @@ async function followingDeep(db, seed_ids, depth) { return x; } -async function followers(db, visible_users, id) { - if (g_followers_cache[id]) { - return g_followers_cache[id]; - } - var results = visible_users.filter(user => g_following_cache[user] && g_following_cache[user].has(id)); - g_followers_cache[id] = results; - return results; -} - async function getAbout(db, id) { var o = await db.get(id + ":about"); const k_version = 4; @@ -354,9 +345,8 @@ async function refresh(selected) { 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 => getVotes(db, id).then(results => results.length ? app.postMessage({votes: results}) : null))); 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}); } diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index 3a65a219..c4d3ff78 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -90,16 +90,6 @@ function processMessages() { if (event.data.user.user == g_data.whoami) { updateEditUser(); } - } else if (key == 'followers') { - if (!g_data.users[event.data.followers.id]) { - Vue.set(g_data.users, event.data.followers.id, {}); - } - if (!g_data.users[event.data.followers.id].followers) { - Vue.set(g_data.users[event.data.followers.id], 'followers', {}); - } - for (let user of event.data.followers.users) { - Vue.set(g_data.users[event.data.followers.id].followers, user, true); - } } else if (key == 'following') { if (!g_data.users[event.data.following.id]) { Vue.set(g_data.users, event.data.following.id, {}); @@ -109,6 +99,13 @@ function processMessages() { } for (let user of event.data.following.users) { Vue.set(g_data.users[event.data.following.id].following, user, true); + if (!g_data.users[user]) { + Vue.set(g_data.users, user, {}); + } + if (!g_data.users[user].followers) { + Vue.set(g_data.users[user], 'followers', {}); + } + Vue.set(g_data.users[user].followers, event.data.following.id, true); } } else if (key == 'broadcasts') { g_data.broadcasts = event.data.broadcasts;